0

Output error

This is my new code: total = 0 age = int(input()) i = 0 while i < 5: i = i + 1 if age < 3: 'continue' total += 100 print(total) For input: 1 2 1 20 2 It shows 100 Whereas, For input: 20 32 2 1 2 It shows 100 but it should show 200. Please help https://code.sololearn.com/cVuvG3aL145o/?ref=app

20th Feb 2023, 2:03 PM
master tech gamer A2Z kansal's,king
master tech gamer A2Z kansal's,king - avatar
6 Antworten
+ 7
to *all of you* > please use propper indentation. this means that *4 spaces* are recommended. please read the pep-0008: https://peps.python.org/pep-0008/#indentation > using just 1 or 2 spaces is horrible for reading.
20th Feb 2023, 7:52 PM
Lothar
Lothar - avatar
+ 3
Your code takes only single input. Input command is before loop. And also no, it may output 500 or 0 For python codes, always save code and share link. Indentation is much important.
20th Feb 2023, 2:11 PM
Jayakrishna 🇮🇳
+ 3
I can only say the errors after looking at your update code. See : while i<5 : i += 5 age = int( input () ) This will accept 5 inputs. But while i < 5 : i += 1 age = int( input()) will accept single input. And loop is no use there.. This is depends on your instructions positions and it's indentations... continue is a valid command but 'continue' is just a string. edit: master tech gamer A2Z kansal's,king if you dont know, this may help you, to share links 👇 https://www.sololearn.com/post/75089/?ref=app
20th Feb 2023, 2:25 PM
Jayakrishna 🇮🇳
+ 1
# notify after any changes to know others.... total = 0 i = 0 while i < 5: i = i + 5 # adding 5 so loop runs only ones age = int(input()) if age < 3: # this is not inside loop. Run afrer loop 'continue' # this is just string, not command total += 100 print(total)
20th Feb 2023, 3:52 PM
Jayakrishna 🇮🇳
+ 1
total = 0 i = 0 while i < 5: i = i + 1 age = int(input()) if age < 3: continue total += 100 print(total) #check this corrected code with yours.
20th Feb 2023, 3:55 PM
Jayakrishna 🇮🇳
0
Ok thanks and if I arrange it in the loop It still gives output 0 instead of 200
20th Feb 2023, 2:18 PM
master tech gamer A2Z kansal's,king
master tech gamer A2Z kansal's,king - avatar