Why it gives an error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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
7 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
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