+ 7

In python if the user doesn't enters a input and simply press submit button. If this is situation then how to set default value?

How can we add value to input if user forget to do it? https://code.sololearn.com/c1SFki1nKU1O/?ref=app

20th May 2020, 1:02 PM
NARESH KUMAR
NARESH KUMAR - avatar
26 Antworten
+ 9
B.Naresh Kumar before you hit the submit button you have to follow some steps only in sololearn Since, your code takes 3 input from the user. So while submitting the values you enter the values in new line Eg - 42 23 32 So, if you want that your code gives the output even if the user doesn't input any value(default value), then still you have to enter space according to your input Eg - (Enter) (Enter) (Enter) I think your doubt may be cleared now😊😊😊 https://code.sololearn.com/cXNshChP7mzu/?ref=app
20th May 2020, 3:32 PM
Divyanshu Singh
Divyanshu Singh - avatar
+ 16
choice = input("") or 7 choice takes input if not empty, otherwise 7.
20th May 2020, 1:43 PM
Jayakrishna 🇮🇳
+ 8
Divyanshu Singh u satisfied me😊
20th May 2020, 4:54 PM
NARESH KUMAR
NARESH KUMAR - avatar
+ 6
Most welcome brother. Feel free to ask anything related to Python language
20th May 2020, 4:57 PM
Divyanshu Singh
Divyanshu Singh - avatar
+ 6
Divyanshu Singh sure bro😊😊
20th May 2020, 5:02 PM
NARESH KUMAR
NARESH KUMAR - avatar
+ 5
#B.Naresh Kumar look at this once: #if only single input needed, use num1=int(input() or 70) #for more inputs use try,catch like try: num2=int(input()) num3=int(input()) except : num2 =30 num3 =20
20th May 2020, 2:35 PM
Jayakrishna 🇮🇳
+ 5
One thing I like about Python is precisely the fact that you can do this in a rather elegant way. For example if input is stored in variable n you can do: n=int(input() or 5) If the user just press Submit, then n will be set to 5
21st May 2020, 10:17 PM
Uni
Uni - avatar
+ 4
n = [1,2,3] choice = input('Pick a number from 1-3') if choice == '' or choice not in n: choice = 1
20th May 2020, 1:10 PM
Slick
Slick - avatar
+ 4
Slick and Jayakrishna🇮🇳 please give your answer according my code .I edited the qn.😊
20th May 2020, 2:10 PM
NARESH KUMAR
NARESH KUMAR - avatar
+ 4
You must be a beast with another language haha. Python uses "None" in place of "null"
20th May 2020, 2:13 PM
Slick
Slick - avatar
+ 4
Slick it doesn't worked☹️
20th May 2020, 2:19 PM
NARESH KUMAR
NARESH KUMAR - avatar
+ 4
Slick replaced but literal error☹️
20th May 2020, 2:53 PM
NARESH KUMAR
NARESH KUMAR - avatar
+ 4
Theres a bunch of ways to do this but im not trying to rewrite your code my man. You just called in a squad so Ill write my version of the program and you can see if theres anything to implement.
20th May 2020, 3:02 PM
Slick
Slick - avatar
+ 4
I did not find any mistake. It's working well. May be , I don't understand what you are asking!😀
20th May 2020, 3:09 PM
Brahmeswara Rao
Brahmeswara Rao - avatar
+ 3
B.Naresh Kumar what problem you are getting still.. If only single input need then use or method.. Because a press enter treated as empty string... If multiple inputs, then go for try catch method,...
20th May 2020, 3:06 PM
Jayakrishna 🇮🇳
+ 3
Try this dude: a = input() if len(a) is 0: a = 'value' I think this the possible way in Sololearn
20th May 2020, 3:25 PM
Subash
Subash - avatar
+ 3
22nd May 2020, 11:20 AM
NARESH KUMAR
NARESH KUMAR - avatar
+ 2
Python is also case sensitive sir. Exactly whats in the quotes above is what needs to be replaced
20th May 2020, 2:20 PM
Slick
Slick - avatar