Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6
👍 Just to put it explicit: Because int() can accept string such as "123" but it cannot accept string such as "". So in version 2, the error "base 10" appears, when your input1 is "" and the line int(input1) is reached. And in version 1, your if conditon is preventing int("") to happen, so there won't be the error message.
27th Jun 2020, 7:54 AM
Gordon
Gordon - avatar
+ 6
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 if int(hours) >= a: print("yes") also if int(hours) == a: print("yes")
25th Jun 2020, 6:13 AM
BroFar
BroFar - avatar
+ 6
What do you see with int("")?
27th Jun 2020, 7:48 AM
Gordon
Gordon - avatar
+ 5
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 error is not in this case! If you give no output or not a number, then the int part will show an error! print(len(str("")) == 0) Is not where your code is wrong
25th Jun 2020, 5:57 AM
Namit Jain
Namit Jain - avatar
+ 5
Try starting a blank code and run with only int("")
27th Jun 2020, 6:00 AM
Gordon
Gordon - avatar
+ 5
What does it say?
27th Jun 2020, 7:49 AM
Gordon
Gordon - avatar
+ 4
Why are you using 'int' in the first condition and 'len' in the second?
25th Jun 2020, 5:36 AM
Namit Jain
Namit Jain - avatar
+ 4
What do you want to achieve? Can you give some input - output pair examples
27th Jun 2020, 3:49 AM
Gordon
Gordon - avatar
+ 4
What does it mean?
27th Jun 2020, 7:51 AM
Gordon
Gordon - avatar
+ 3
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Is your question solved already?
25th Jun 2020, 5:45 AM
Namit Jain
Namit Jain - avatar
+ 3
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 let's look at this a bit different as int is a float not a natural number though it may appear to look as such thus you are trying to compare them as equals.... https://code.sololearn.com/cSIq2GujVmvf/?ref=app
25th Jun 2020, 5:55 AM
BroFar
BroFar - avatar
+ 3
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 your order of operations were skewed input1=input() if not input1: print("input1: Please enter a value") elif int(input1)>=1001: print("Input must be less than 1000") else: print("Input1 :",input1)
25th Jun 2020, 6:28 AM
BroFar
BroFar - avatar
+ 3
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 In your second version, after input1 = input() add print(input1) what do you see?
27th Jun 2020, 5:52 AM
Gordon
Gordon - avatar
27th Jun 2020, 8:08 AM
Gordon
Gordon - avatar
+ 2
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 the second code is not addressing len but base '10' error
25th Jun 2020, 5:32 AM
BroFar
BroFar - avatar
+ 2
Use try and except in these cases Instead of using if elif and else
25th Jun 2020, 5:54 AM
Namit Jain
Namit Jain - avatar
+ 2
import re pattern = r"spam" if re.match(pattern, "spamspamspam"): print("Match") else: print("No match")
26th Jun 2020, 10:21 AM
Lloyd L Conley
Lloyd L Conley - avatar
+ 1
You will have to convert it into a string then find its length! See this! This will help you https://code.sololearn.com/cu97E23K8Zmg/?ref=app
25th Jun 2020, 5:41 AM
Namit Jain
Namit Jain - avatar
+ 1
Have a look at this! If the input is empty then it will show an error https://code.sololearn.com/cpZ4gT214aHe/?ref=app
25th Jun 2020, 5:52 AM
Namit Jain
Namit Jain - avatar
+ 1
I think you you have already understood the error by now. Your second code can be fixed by adding "0" to input1 in the 1st if block. Like this: if int(input1 + "0") >= 1001:
25th Jun 2020, 3:42 PM
Tricker