0
var1 = 6
var2 = int(input())
if var2 > var1:
    print("Greater")
else:
    print("Smaller")

Hey there I started learning python recently, currently I am using VS Code but I encountered a problem while learning IF ELSE, in the above code it is showing "invalid literal for int() with base 10" while in other compiler it works fine. How do I fix it.

Saurabh
  • 1
  • 1

2 Answers2

0

Possibly this answer helps out.

Or you may first float() the input() and then do the int(). You should also indicate in the input() which type of number you expect, like 8 or 8.8 or both.

var1 = 6
inp = input('Enter a number(e.g. 8 or 8.8):')
print(type(inp))
inpf = float(inp)
print(type(inpf))
var2 = int(inpf)
if var2 > var1:
    print("Greater")
else:
    print("Smaller")
chiefenne
  • 565
  • 2
  • 15
  • 30
0

It should be like this:

var1 = 6
var2 = float(input())
if var2 > var1:
    print("Greater")
else:
    print("Smaller")

int() only accepts integer.

Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13