Python Forum
Having a problem with simple code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having a problem with simple code
#1
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")
Reply
#2
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")
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with simple code JacobSkinner 1 334 Mar-18-2024, 08:08 PM
Last Post: deanhystad
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 491 Nov-07-2023, 04:32 PM
Last Post: snippsat
  A simple problem, how best to solve it? SuchUmami 2 731 Sep-01-2023, 05:36 AM
Last Post: Pedroski55
  help me simple code result min and max number abrahimusmaximus 2 914 Nov-12-2022, 07:52 AM
Last Post: buran
  Simple encoding code ebolisa 3 1,462 Jun-18-2022, 10:59 AM
Last Post: deanhystad
  How to solve this simple problem? Check if cvs first element is the same in each row? thesquid 2 1,242 Jun-14-2022, 08:35 PM
Last Post: thesquid
  How would you (as an python expert) make this code more efficient/simple coder_sw99 3 1,817 Feb-21-2022, 10:52 AM
Last Post: Gribouillis
  Simple code question about lambda and tuples JasPyt 7 3,341 Oct-04-2021, 05:18 PM
Last Post: snippsat
Big Grin question about simple algorithm to my problem jamie_01 1 1,690 Oct-04-2021, 11:55 AM
Last Post: deanhystad
  My simple code don't works !! Nabi666 1 1,620 Sep-06-2021, 12:10 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020