ans = sum([int(i) for i in isbn if i.isdigit()])
print ans
Should work for you
The above is the same as saying
ans = 0
for i in isbn:
if i.isdigit():
ans += int(i)
print ans
Domanda
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:
this is where I am stuck I need help in order to get them all to add together
Soluzione
ans = sum([int(i) for i in isbn if i.isdigit()])
print ans
Should work for you
The above is the same as saying
ans = 0
for i in isbn:
if i.isdigit():
ans += int(i)
print ans