Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tip Program
#1
Hello! This is actually my first time posting on a forum, ever haha. Well I'm going through a book on python, thought I understood naming variables, but found that I don't know how to fix NameError: name 'tip_15' is not defined

# Tip Buddy
# Have User enter bill amount
# output tip amount and
# bill total
# Patrick Crowley
# 8/7/2017

# gather information from user
bill = float (input ("Please enter amount shown on bill."))

# output tip amount by 15% and 20%

tip20 = bill * 0.2
tip15 = bill * 0.15
# 15%
print ("\n\nIf your service was satisfactory today,", \
tip_15 , "is a resonable tip Based on 15%")
print ("Your total would be:", bill + tip_15)

#20
Reply
#2
tip15 on line#14 vs tip_15 on line#18
do you see the difference?
Reply
#3
If you look at the name you gave to bill * 0.15 is 'tip15'. When you use it again you use 'tip_15'. If you get rid of the underscore on the last line then it should work. Smile Smile
Reply
#4
Ohh yes i do see it now... thank you. i actually went through and changed the variable names completely and it worked, but i will triple check next time so i dont sound like a dope.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020