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)
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เผ๊ง
+ 4
Special Thanks to all
My doubt is clear now..
+ 3
๐๐ข๐ข๐๐จ ๐๐ก๐๐ฒ๐๐ฅ
Didn't understood clearly and can "None" here cannot be used?
+ 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.
+ 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)
+ 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.
+ 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