-2

I'm trying to complete an assignment for school where I have to ask the user if they are seeing a movie in 3D and what their age is, and compute the price of the ticket based on their answers. For some reason regardless of what they put for 'type', it comes out as if they said yes. What am I doing wrong?

# Base Price: 13, Child Discount: 50%, Senior Discount: 25%, 3D Surcharge: 35%

base_price = 13
child_discount = .5
senior_discount = .75
surcharge3d = 1.35
type = (input("Is the movie you are seeing in 3D?\n"))
age = eval(input("How old are you?\n"))

# Determine the price of the movie ticket

if type == 'No' or 'no':
    if age <= 12:
        total = base_price * child_discount
    elif 12 < age < 65:
        total = base_price
    else:
        total = base_price * senior_discount
elif type == 'Yes' or 'yes':
    if age <= 12:
        total = base_price * surcharge3d * child_discount
    elif 12 < age < 65:
        total = base_price * surcharge3d
    else:
        total = base_price * surcharge3d * senior_discount

# Display total cost

print("The total cost of your ticket is", round(total, 2), "dollars.")
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
ahap13
  • 1
  • Does this answer your question?: https://stackoverflow.com/questions/17902492/python-testing-whether-a-string-is-one-of-a-certain-set-of-values – Mr PizzaGuy Jan 16 '21 at 22:24

1 Answers1

0

When using if else statement, you should use two conditions around or such as:

if type == 'No' or type == 'no'

Long Explanation: When you compare a single string such as if ('no'), this will always give true as it is a valid value and will give false is there is a 'none' value. Basically any valid value counts as a truthy value and hence first your if statement executes, then your elif, hence it stores finally elif's total.

Two suggestions:

  1. type is a builtin function, dont use it. However, thats not the problem.
  2. You can use .lower() function on your string and avoid using 'Yes' and 'yes' two times.
Nitish
  • 392
  • 2
  • 7