0
How to take another Input after the code running in Python
After i run my code that -for instance- takes an input from the user he failed to enter a valid input and i want the user to Re-Try and input again
14 Antworten
+ 3
Please share us your code
+ 2
You cannot ask for inputs at different times on Sololearn. You can try the work around of asking for multiple inputs and then having the user answer those inputs on seperate lines (there's instructions on the popup), but you have to be sure to state what inputs you are expecting in advanced (via a docstring or comment in the beginning of the file).
If the user inputs something wrong, you will just have to end the program unfortunately (though of course you can still handle what will be output based on that try/except block you make).
+ 2
Herobrine amazing.. wonderful effort .. not what am asking .. thank you tho
+ 1
Sakshi it's not for specific code .. but consider this
name = input( )
if name == 'Amr'
print('okay')
else :
print('invalid name')
so for this code it will give the user a try to insert a name so he enters either 'Amr' or other string so it outputs either 'okay' or 'invalid name' HERE
i need to gave him a second change to enter other name ..
+ 1
Amr Monsef You specifically tagged "codeplayground", so I was going based off that. There are a plethora of different ways you can go about doing so and I still gave a hint in my previous reply about try/except. You can also just use a loop and/or use a conditional.
+ 1
Amr Monsef example: if you input two numbers then when the pop up show on sololearn playground to take the input the you enter like this:-
10
20
Ok, you enter the first number then enter and put again second number, hope you understand what I mean
+ 1
Welcome I will try to understand your problem
+ 1
By using a while loop. the input function has to be placed in the while loop.
+ 1
If user didnt type the input you want you can while loop like this.
name = input("type 1, 2, or 3")
while True:
if name in [1,2,3]:
break
else:
name = input("input wrong. Type 1, 2, or 3")
0
Justice yup..my bad
0
Sakshi i understood what you meant but i think you didn't :) .. i mean after the code running ... after i hit RUN i need the prompt to be back again to enter a New input
0
MD. Omar Faruk Maruf Bertram Rayhan gonna try this ..