Python Forum

Full Version: Having a problem with simple code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Well, when i set S as 9 and G as 3 python print "a" what is correct, but when i set S with a number like 42 and G as a number with the first digit greater than the first of 42 (like 6), so python is saying 42 < 6 but 72 > 6 and the code is taking 6000 < 700 but 8000 > 800. Here's the code:

S = input ("S?")
G = input ("G?")

if S > G:
         print ("a")
elif G > S:
           print ("b")
elif S == G:
            print ("c")
input() returns str. You need to convert it to int before comparing. Also your indentation is bit off.

S = int(input ("S?"))
G = int(input("G?"))
 
if S > G:
    print ("a")
elif G > S:
    print ("b")
elif S == G:
    print ("c")