0

Looking help with the code below, it seems that adding m_Time on the first if statement makes the program run incorrectly. Just looking at the first if statement, the rest works as intended. Any help regarding this would be appreciated.

tick_Num = float(input("How many tickets are you buying? "))
day = input("What day do you want to watch the movie? Enter mon for Monday etc. ")
m_Time = int(input("What time is the movie? Enter 0000 to 2359: "))


if 200 <= m_Time <= 1600 and tick_Type == "child" and day != "sat" or day != "sun":
    print("You should be in school, not at the movies.")
elif tick_Type == "child" and day == "mon" or day == "tue" or day == "wed":
    total = 8 * tick_Num * 0.75
    print("Total: $" + format(total,",.2f"))
elif tick_Type == "senior" and day == "mon" or day == "tue" or day == "wed":
    total = 9 * tick_Num * 0.75
    print("Total: $" + format(total,",.2f"))
elif tick_Type == "general" and day == "mon" or day == "tue" or day == "wed":
    total = 10 * tick_Num * 0.75
    print("Total: $" + format(total,",.2f"))
elif tick_Type == "child" and day == "thu" or day == "fri" or day == "sat":
    total = 8 * tick_Num * 1
    print("Total: $" + format(total,",.2f"))
elif tick_Type == "senior"  and day == "thu" or day == "fri" or day == "sat":
    total = 9 * tick_Num * 1
    print("Total: $" + format(total,",.2f"))
elif tick_Type == "general" and day == "thu" or day == "fri" or day == "sat":
    total = 10 * tick_Num * 1
    print("Total: $" + format(total,",.2f"))
elif tick_Type == "child"  and day == "sun":
    total = 8 * tick_Num * 0.9
    print("Total: $" + format(total,",.2f"))
elif tick_Type == "senior" and day == "sun":
    total = 9 * tick_Num * 0.9
    print("Total: $" + format(total,",.2f"))
elif tick_Type == "general" and day == "sun":
    total = 10 * tick_Num * 0.9
    print("Total: $" + format(total,",.2f"))
elif day == "mon" or day =="tus" or day == "wed":
    total = 10 * tick_Num * 0.75
    print("Total: $" + format(total,",.2f"))
elif day == "thu" or day =="fri" or day == "sat":
    total = 10 * tick_Num * 1
    print("Total: $" + format(total,",.2f"))
elif day == "sun":
    total = 10 * tick_Num * 0.9
    print("Total: $" + format(total,",.2f"))

else:
    print("NO TICKET: invalid day")
4
  • what do you mean by "runs incorrectly"? Commented Oct 3, 2020 at 3:55
  • @FrankYellin It ran incorrectly when I input : Senior, 1, mon, 600. It is supposed to not run the first if statement based off of the input but still does for some reason. Commented Oct 3, 2020 at 4:05
  • operator precedence ... Commented Oct 3, 2020 at 4:11
  • You shouldn't write an elif for every possible combination of conditions. You should create dictionaries like {'child': 8, 'senior': 9, 'general': 10} and get the factors for the price from there. Commented Oct 3, 2020 at 4:32

1 Answer 1

1

Assuming I identified your problem correctly, your first clause 200 <= m_Time <= 1600 and tick_Type == "child" and day != "sat" or day != "sun" would always be True if day != 'sun' is True because of the way Python calculates booleans. What I believe you want is something like this:

if 200 <= m_Time <= 1600 and tick_Type == "child" and day != "sat" and day != "sun":
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.