2014-02-12 21 views
0
start = " " 
multiplynum = 11 
protectedisbn = " " 
while start.lower() != "n": 
print("Welcome to the isbn number protector!") 
start = input ("Would you like to protect your isbn number? (y/n) ") 
if start == "y": 
    isbn = input("Please input your 10 digit isbn number. ") 
    if len (isbn) != 10: 
     print("I am sorry but you need to enter a 10 digit isbn.") 
    for ch in isbn: 

这就是我坚持我需要帮助,以让他们都加在一起我需要在输入的isbn中添加所有字符我该怎么做? (蟒蛇)

回答

1
ans = sum([int(i) for i in isbn if i.isdigit()]) 
print ans 

应该为你工作

以上是相同的话说

ans = 0 
for i in isbn: 
    if i.isdigit(): 
     ans += int(i) 
print ans 
+0

那么我会输入什么来打印呢? – Xxbat99xX

+0

将它指定给ans,打印它 –

+0

,我会指定它如何? (对不起,我是一个小老鼠不是很多,但我不明白我将如何分配这一点的代码) – Xxbat99xX

相关问题