The code incorrectly calculates the sum of the digits of the number. For example, if you enter 157, then the output will be LOCK | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The code incorrectly calculates the sum of the digits of the number. For example, if you enter 157, then the output will be LOCK

https://code.sololearn.com/c9JM7vSLRwvt/?ref=app

17th Apr 2021, 10:03 AM
Paula Voqy
Paula Voqy - avatar
6 Answers
+ 2
The problem is actually your second term bracket. You shouldn't and two numbers, because it will return True/False (1 and 1) == True # True is also 1 so instead you can just remove the bracket and the and c // 100 + c // 10 + c % 10 == 13: however, the second term will be wrong, so you need to adjust it a bit c // 100 + c // 10 % 10 + c % 10 == 13: so let's say 157, 157 //10 = 15 15 % 10 = 5, which is the number you want Another alternative and maybe easier way is to loop the string and plus the int of each character c = input() # didn't convert to int here total = 0 for char in c: total += int(c) And here is the standard way everyone getting the sum of tbe digits c = int(input()) total = 0 while c > 0: total += c % 10 c //= 10
17th Apr 2021, 10:40 AM
Hoh Shen Yien
Hoh Shen Yien - avatar
+ 1
Polina Voqy What do you expect and what are you doing here? https://code.sololearn.com/cw6Cz4ogRgPk/?ref=app
17th Apr 2021, 10:32 AM
A͢J
A͢J - avatar
+ 1
Thanks for the help
17th Apr 2021, 10:40 AM
Paula Voqy
Paula Voqy - avatar
0
It is lock. When you input number less than 100 and more than 999 then you'll got FALSE. If sum of digits of a number is 13 output is ENTER. In other occasions LOCK. But when I write 157 or 247 and also some more, it outputs LOCK
17th Apr 2021, 10:38 AM
Paula Voqy
Paula Voqy - avatar
0
Thanks for the explanation
17th Apr 2021, 10:42 AM
Paula Voqy
Paula Voqy - avatar
0
Я из России
19th Apr 2021, 6:45 AM
Ar1 Pro
Ar1 Pro - avatar