[英]two digit multiplication (for loops)
def getProduct(n):
product = 1
while (n != 0):
product = product * (n % 10)
n = n // 10
return product
calc = list()
for number in range(10, 100):
num = getProduct(number)
if number == 2 * num:
calc.append(number)
print(calc)
So, the question is to have a column of two digit numbers, which is equal to the (product of the two digits * 2).所以,问题是有一列两位数,等于(两位数的乘积 * 2)。 How should I solve this problem?
我应该如何解决这个问题?
i dont know what you mean but im guessing you need code for a two digit calulator我不知道你的意思,但我猜你需要一个两位数计算器的代码
def multiply(x, y):
return x * y
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print(num1, "*", num2, "=", multiply(num1, num2))
def getProduct(n):
product = 1
if (n != 0):
product = product * (n % 10) * (n//10)
return product
calc = list()
for number in range(10, 100):
num = getProduct(number)
if number == 2 * num:
calc.append(number)
print(calc)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.