0

Can you check my code and please tell me why NameError: name 'Yes' is not defined occurs.

"""This code prints how many tickets user gets depending on userDollar"""
FirstClassPrice = 44
userDollar = int(input("Please enter the number of dollars you want to 
spend:"))
userDollarConvert = 100 * userDollar
userTick = userDollarConvert // FirstClassPrice

#Input and output of the code showing the change
userChange = userDollarConvert % FirstClassPrice
print("Your Change: $0." + str(userChange))
print("Number of First Class Tickets You Have:" + str(userTick))

#100 Tickets can be changed into 1 dinner ticket
if 100 <= userTick:
  userChoice = input("Would you like to change 100 tickets into a free 
dinner ticket? Yes or No only.")
  if userChoice == ("Yes"):
    DinnerTicket = 100(userTick)
    print("You now have:" + DinnerTicket // userTick + "DinnerTicket(s)")
    print("You have" + DinnerTicket % userTick + "Tickets remaining")
Taewon Kim
  • 1
  • 1
  • 1
  • Line 3 and 17 made 2 seperate sentences because those lines were too long to fit into the question bar thanks! – Taewon Kim Jun 22 '17 at 19:00
  • You are on Python 2, therefore, you should be using `raw_input`. `input` in Python 2 `eval`s the string the user enters, which causes your error. – juanpa.arrivillaga Jun 22 '17 at 19:00
  • He is using print with () so it's python3 not python2 – Alex Lucaci Jun 22 '17 at 19:02
  • @AlexLucaci `print()` is still valid syntax on Python 2, although the semantics can be different (you may inadvertently create a `tuple`, for example). So, just because there are parenthesis following a `print` token doesn't guarantee that you are on Python 3 at all. – juanpa.arrivillaga Jun 22 '17 at 19:04
  • In the future, please at least try to google to find an answer before creating a new question on StackOverflow. The duplicate target above was the second hit I got when googling your title verbatim. The first hit was *another* question that was linking to the same duplicate. – juanpa.arrivillaga Jun 22 '17 at 19:05
  • @juanpa.arrivillaga you are right, my mistake – Alex Lucaci Jun 22 '17 at 19:06

1 Answers1

0

In Python 2, try raw_input() instead of input(). It returns a string instead of trying to evaluate the input as code.

kichik
  • 33,220
  • 7
  • 94
  • 114