+ 1

How do i add loop in my python code ??

Hi, idk why but my code is not in loop even tho i added ‘while’. What’s the problem in this code ? https://code.sololearn.com/cpmiHQe7Nwdh/?ref=app

11th Nov 2022, 11:36 AM
milna
2 Respostas
+ 3
On an ordinary python interpreter on pc/mac/browser, your code would work perfectly! Unfortunately running python in the sololearn online compiler seems to work differently. Unlike the usual terminal style input, it expects ALL the input to be entered at the start of the code and keeps it in a file somewhere. As the code runs and encounters the input() function, it reads a line from that file as it's input. For your program, this means you'll need to input many words (Rock/Paper/Scissors) depending on how many games you'd like to play. Since your program accepts input indefinitely, it stops at the end of the input file and raises an EOF Error (End of file) when there's no more input words. I'd suggest adding an extra condition in your if-elif chain to exit the loop when the player is done playing: elif player == "End": print("Thanks for playing") break And your input (entered in the pop-up box) would be something like: Rock Rock Paper Scissors Rock End
11th Nov 2022, 12:14 PM
Mozzy
Mozzy - avatar
+ 3
You run this in SoloLearn or your PC/laptop? in SoloLearn we have to provide all necessary inputs one time, before running the code. In PC/laptop interactive input is supported. I gave it 3 inputs (Rock, Paper, Scissors) to test and it works (in SoloLearn). (Edit) Lesson 41.1 onwards covers exception handling technique you can use to handle input error - where there be no input or no more input available.
11th Nov 2022, 12:10 PM
Ipang