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

14th Mar 2023, 11:59 AM
Amr Monsef
Amr Monsef - avatar
14 Réponses
+ 3
Please share us your code
14th Mar 2023, 12:24 PM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 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).
14th Mar 2023, 12:37 PM
Justice
Justice - avatar
14th Mar 2023, 2:42 PM
Herobrine
Herobrine - avatar
+ 2
Herobrine amazing.. wonderful effort .. not what am asking .. thank you tho
14th Mar 2023, 2:44 PM
Amr Monsef
Amr Monsef - avatar
+ 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 ..
14th Mar 2023, 12:28 PM
Amr Monsef
Amr Monsef - avatar
+ 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.
14th Mar 2023, 12:49 PM
Justice
Justice - avatar
+ 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
14th Mar 2023, 2:30 PM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 1
Welcome I will try to understand your problem
14th Mar 2023, 3:09 PM
Herobrine
Herobrine - avatar
+ 1
By using a while loop. the input function has to be placed in the while loop.
15th Mar 2023, 6:15 AM
Md Omar Faruk Maruf
Md Omar Faruk Maruf - avatar
+ 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")
15th Mar 2023, 9:17 AM
Bertram Rayhan
Bertram Rayhan - avatar
0
Justice it's not for Sololearn codeplayground im asking in general Python language what if the user inputs wrong input for my app how to give him the input prompt again
14th Mar 2023, 12:41 PM
Amr Monsef
Amr Monsef - avatar
0
Justice yup..my bad
14th Mar 2023, 12:49 PM
Amr Monsef
Amr Monsef - avatar
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
14th Mar 2023, 2:34 PM
Amr Monsef
Amr Monsef - avatar
15th Mar 2023, 11:02 AM
Amr Monsef
Amr Monsef - avatar