#Initialising Variables
inputISBN = input("What is your 10 digit ISBN number? ")
itemInList = 0
timesNumber = 11
listISBN = []
timesISBN = []
#Checking if the input is only numbers
if len(inputISBN) == 10 and inputISBN.isdigit() :
while itemInList < 10 :
listISBN.append(inputISBN[itemInList])
itemInList = itemInList + 1
print(listISBN)
itemInList = 0
while itemInList < 10 :
num = listISBN[itemInList]
int(num)
timesISBN.append(num * timesNumber)
itemInList = itemInList + 1
timesNumber = timesNumber - 1
print(timesISBN)
else:
print("Invalid input")
HALP只打印输入数字11次,然后打印10次ARRAGGH 对不起,没有什么可说的了,我想添加更多细节。 此代码用于将您的输入乘以11然后10等等,但它只复制了那么多的数字。我不明白为什么这不起作用
答案 0 :(得分:0)
您需要存储int()
电话的返回值;否则num
值不受影响:
num = listISBN[itemInList]
num = int(num)
答案 1 :(得分:0)
这是一种更简单的方法:
>>> inputISBN=input("What is your 10 digit ISBN number? ")
What is your 10 digit ISBN number? 1203874657
>>> if(len(inputISBN)==10 and inputISBN.isdigit()):
... timesISBN = [int(i)*j for i,j in zip(inputISBN,range(11,1,-1))]
... print(timesISBN)
... else:
... print("Invalid input")
...
[11, 20, 0, 24, 56, 42, 20, 24, 15, 14]