Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 unexpected output
#1
my question here
I'm very new to Python and I created a simple number guessing game and for some reason when i enter a number that is 100 or higher it will say Higher. Why?

VarNum = "0"
while(VarNum != "27"):
VarNum = input("Guess my number from 1-99: ")
print("Your answer is:", VarNum)
if (VarNum > "27"):
print("Lower")
elif (VarNum < "27"):
print("Higher")
elif (VarNum == "27"):
print("Congratulations! You guessed my number!")
metulburr wrote Apr-25-2017, 03:56 PM:
Please use a better subject title than "Help :D"
Use meaningful, specific subject headers
Quote
#2
you are working with str, not int, which is wrong. you should work with numbers, not strings. when comparing strings it compares first char of str1 with first char of str2, so if you enter '100' (that is str), it wil compare char '1' with first char of '27', i.e. '2'. '1' comes before '2' so it's says 'Higher'
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Unexpected output palladium 4 325 Jan-11-2020, 03:26 PM
Last Post: palladium
  Unexpected output: if statement CabbageMan 1 284 Sep-04-2019, 04:12 PM
Last Post: ThomasL
  Unexpected Output using classes and inheritance langley 2 420 Jul-04-2019, 09:33 AM
Last Post: langley
  float multiplication - unexpected output inesk 3 742 Dec-11-2018, 10:59 AM
Last Post: DeaD_EyE
  Unexpected output when searching for a string from os.popen output FujiJean 3 874 Oct-02-2018, 11:39 AM
Last Post: volcano63
  Unexpected twice output Samo 3 769 Sep-29-2018, 10:00 PM
Last Post: Samo
  Unexpected simpy simulation output bakas 1 1,750 Sep-07-2018, 01:14 AM
Last Post: scidam
  unexpected output for global variable bhdebasish 1 763 Aug-22-2018, 04:55 PM
Last Post: Larz60+
  A little unexpected output from a while loop linuxnoob 3 849 Jul-17-2018, 01:02 AM
Last Post: gontajones
  Unexpected output, TypeError and traceback error fier259 2 1,031 May-06-2018, 10:52 PM
Last Post: fier259

Forum Jump:


Users browsing this thread: 1 Guest(s)