Home > Net >  trying to get my code to reconise upper and lower case input from the user [duplicate]
trying to get my code to reconise upper and lower case input from the user [duplicate]

Time:10-03

Hi im new to coding and still learning what im trying to do is when the user typed Y/y or N/n the code gives the same outcome currently its okay with N/n but when I type in Y it works fine, but if I type in y it gives the wrong outcome

print("Welcome to the rollercoaster!")
age = int(input("What is you'r age? "))
height = int(input("What is your height in cm? "))
photo = input("Would you like a photo? please type Y or N ")
if height >= 120:
  print("you can get on this ride!")
  if age <= 12:
    if photo == ("y").upper():
      print ("that will be an extra £3.00 for the photo and £5.00 for the ride, the total now comes to £8.00.")
    else:
      print ("The ticket price is £5.00") 
  elif age < 18:
    print ("The ticket price is £7.00")
  else:
    print ("The ticket price is £8.00")
else:
  print("you are not tall enough to ride this ride")

ideally I want it both to say >print ("that will be an extra £3.00 for the photo and £5.00 for the ride, the total now comes to £8.00.")< no matter if y or Y is typed

CodePudding user response:

You are always comparing to "Y"; try replacing

if photo == ("y").upper():

with

if photo.upper() == "Y":

CodePudding user response:

Upper makes the string capitalized, try to use isupper instead. https://www.kite.com/python/answers/how-to-check-if-a-character-is-uppercase-in-python

  • Related