-2
Question = input("How much money did Kingsman make this weekend?:")
if Question > "10000000":
    print("Wow! What an opening!")
elif Question >= "5000000" <= "9000000":
    print("Hey! Not a bad start!")
elif Question < "5000000":
    print("Are you happy with this result?")

If I was to say that kingsman made $4,000,000 it outputs the message for when the movie makes over 10mil, but the really weird thing is that when I input $1 it outputs the message for when the movie makes less than 5mil (as it should) and as I go up to $4,000,000 it displays the output for less than 5mil (as it should). For some reason, the outputs for the same numbers are changing (in this case 4mil) from "wow! what an opening" to "are you happy with this result" and I don't understand why.

Also, I'm not sure if "elif Question >= "5000000" <= "9000000":" is correct. I'm trying to say that when the movie's revenue is in the range of 5mil to 9mil that it should display the message "Hey! Not a bad start!"

AMC
  • 2,642
  • 7
  • 13
  • 35
TaNk
  • 17
  • 4
  • Try running the following snippet: `print("5" < "100", 5 < 100)`. As an aside, variable and function names should generally follow the `lower_case_with_underscores` style. – AMC Apr 14 '20 at 01:25
  • 1
    Does this answer your question? [How can I read inputs as numbers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – AMC Apr 14 '20 at 01:25

2 Answers2

1

You're comparing strings, when you should probably be comparing integers.

elif Question >= "5000000" <= "9000000": is incorrect.

it should be something like:

elif 5000000 <= int(Question) <= 9000000:

oittaa
  • 599
  • 3
  • 16
  • elif "5000000" <= int(Question) <= "9000000": didn't fix the problem, the same thing keeps happening – TaNk Apr 14 '20 at 01:10
  • 1
    Why don't you provide input and output? We can't magically know what's happening. And why are you still comparing strings to integers? – oittaa Apr 14 '20 at 01:18
0

You can even just convert the input into an integer format by putting the int() over the input().

Question = int(input("How much money did Kingsman make this weekend?: "))

Then you can compare the output properly with integers.

if Question > 10000000:

You won't have an issue with your parameters anymore. The reason your program would respond differently because you were comparing string input with other string input. The reason it still did the comparison without throwing any errors is because of its unicode value.

Ex. Program:

print('apple' == 'Apple')
print('apple' > 'Apple')
print('A unicode is', ord('A'), ',a unicode is', ord('a'))

Program Output:

False
True
A unicode is 65 ,a unicode is 97

This is just for reference to why it allowed you to compare 2 strings.

https://www.journaldev.com/23511/python-string-comparison

Dcodeme
  • 16
  • 1
  • Don't use " " quotation marks on the numbers you are comparing. Python will assume that those numbers are a string(words). It will only recognize it as numbers if you compare without the quotation marks. – Dcodeme Apr 14 '20 at 01:25