Python Forum
Tip Program - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Tip Program (/thread-4313.html)



Tip Program - PatrickFCrowley - Aug-07-2017

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



RE: Tip Program - buran - Aug-07-2017

tip15 on line#14 vs tip_15 on line#18
do you see the difference?


RE: Tip Program - martan45 - Aug-07-2017

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


RE: Tip Program - PatrickFCrowley - Aug-07-2017

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.