+ 7

Why it gives an error?

Because none is used to represent the absence of a value. s=int(input()) if s==None: print("Please write something") (Note:- I don't want to use assertions here)

14th Jul 2020, 1:56 PM
Arctic Fox
Arctic Fox - avatar
8 Answers
+ 1
I already added explanation for this also.. Refresh page. Hoping here you taking about on "nothing input". Then that is equal to none or "" (empty string). You can assign these to values to variable in python.. In that code also int(input1) raise error if input is none or if not a number. ꧁༒Rishabh༒꧂
14th Jul 2020, 2:29 PM
Jayakrishna 🇮🇳
+ 4
Special Thanks to all My doubt is clear now..
14th Jul 2020, 2:31 PM
Arctic Fox
Arctic Fox - avatar
+ 3
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Didn't understood clearly and can "None" here cannot be used?
14th Jul 2020, 2:06 PM
Arctic Fox
Arctic Fox - avatar
+ 3
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Gordon's answer I can understand of 1st version. But I didn't get the 2nd one. Which line is preventing to not reach.
14th Jul 2020, 2:12 PM
Arctic Fox
Arctic Fox - avatar
+ 3
Jayakrishna🇮🇳 Then, how does this works? Because you said it's not reached there(getting confused) input1=input() if len(input1)==0: print("Input1: Please enter a value") elif int(input1)>=1001: print("Input must be less than 1000") else: print("Input1 :",input1)
14th Jul 2020, 2:24 PM
Arctic Fox
Arctic Fox - avatar
+ 2
꧁༒Rishabh༒꧂ What error you mean..? S = int(input()) In this if you don't input a number, then it raise exception itself. Don't go to compare statement. On no input, internally for none: int(none) is value error there... Hence again error also. But s = input() if s == None : Will work because variable accept none value.
14th Jul 2020, 2:20 PM
Jayakrishna 🇮🇳
+ 1
basically, when you call for an integer input, the input can only include a number. but if you call for regular input: -you can check isdigit -you can take regular strings and stop when a certain string is put in -if the string meets certain criteria it can be converted to int
14th Jul 2020, 2:23 PM
Slick
Slick - avatar