0

What wrong with the code, nonnegative

entry = 0 sum = 0 print('Enter numbers: ') while entry > 0: entry = int(input()) if entry > 0: sum += entry print (sum)

16th Mar 2021, 8:34 AM
christian lalap
christian lalap - avatar
2 ответов
+ 2
your loop stop as soon as 'entry' is less or equal to zero... and you initialize 'entry' to zero, so your loop is never executed ^^
16th Mar 2021, 8:37 AM
visph
visph - avatar
+ 1
''' if <while> and <if> conditions are the same, why using them both? and if entry is an input, why you declare it as zero first? ''' print('Enter numbers: ') entry = int(input()) sum = 0 if entry > 0: sum += entry else: print("entry must be greater than zero!") print(sum)
16th Mar 2021, 9:25 AM
iTech
iTech - avatar