Python Forum
help (variables) - NameError: name 'Payment' is not defined?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help (variables) - NameError: name 'Payment' is not defined?
#1
I am new to python but why is this code not working?
#Parking Ticket machine
Money = 50

import time
print('''
----------------------------
|Press Enter To Continue   |
|                          |
|                          |
|                          |
|                          |
|               Made by Ben|
----------------------------
''')
input("")
print('''
----------------------------
|How Long Are you Staying? |
| 1 = 1 hour         £1.20 |
| 2 = 2 hours        £2.40 |
| 3 = 3 hours        £3.00 |
| 4 = All Day        £7.00 |
| 5 = All week       £14.00|
----------------------------
''')
In = input (">")
if In == 1:
    Payment = 1.20

if In == 2:
    Payment = 2.40

if In == 3:
    Payment = 3.00

if In == 4:
    Payment = 7.00

if In == 5:
    Payment = 14.00
print(Payment)
print(f"Your current statement is £{Money}")
Error:
Traceback (most recent call last):
File "C:/Users/bcola/Desktop/Other/python/app.py", line 41, in <module>
print(Payment)
NameError: name 'Payment' is not defined


Please help
Reply
#2
input will return str and you are comparing it to int. That is why none of the if statements is executed and Payment is not defined
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
tried this but still not working help.
#Parking Ticket machine
Money = 50

import time
print('''
----------------------------
|Press Enter To Continue   |
|                          |
|                          |
|                          |
|                          |
|               Made by Ben|
----------------------------
''')
input("")
print('''
----------------------------
|How Long Are you Staying? |
| 1 = 1 hour         £1.20 |
| 2 = 2 hours        £2.40 |
| 3 = 3 hours        £3.00 |
| 4 = All Day        £7.00 |
| 5 = All week       £14.00|
----------------------------
''')
In = input(">")
if In == "1":
    Payment = '1.20'

if In == "2":
    Payment = '2.40'

if In == "3":
    Payment = '3.00'

if In == "4":
    Payment = '7.00'

if In == "5":
    Payment = '14.00'
print(Payment)
print(f"Your current statement is £{Money}")
Reply
#4
(Feb-27-2019, 04:39 PM)Vqlk Wrote: tried this but still not working help.
not working is not very descriptive. What exactly is the problem? It does not raise any exception, i.e. works as expected

Output:
---------------------------- |Press Enter To Continue | | | | | | | | | | Made by Ben| ---------------------------- ---------------------------- |How Long Are you Staying? | | 1 = 1 hour £1.20 | | 2 = 2 hours £2.40 | | 3 = 3 hours £3.00 | | 4 = All Day £7.00 | | 5 = All week £14.00| ---------------------------- >1 1.20 Your current statement is £50
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
It deos not work. Here is the code:
#Parking Ticket machine
Money = 50

import time
print('''
----------------------------
|Press Enter To Continue   |
|                          |
|                          |
|                          |
|                          |
|               Made by Ben|
----------------------------
''')
input("")
print('''
----------------------------
|How Long Are you Staying? |
| 1 = 1 hour         £1.20 |
| 2 = 2 hours        £2.40 |
| 3 = 3 hours        £3.00 |
| 4 = All Day        £7.00 |
| 5 = All week       £14.00|
----------------------------
''')
In = input(">")
if In == "1":
    Payment = '1.20'

if In == "2":
    Payment = '2.40'

if In == "3":
    Payment = '3.00'

if In == "4":
    Payment = '7.00'

if In == "5":
    Payment = '14.00'
print(Payment)
print(f"Your current statement is £{Money}")
and the error is :
Traceback (most recent call last):
File "C:/Users/bcola/Desktop/Other/python/app.py", line 41, in <module>
print(Payment)
NameError: name 'Payment' is not defined
Reply
#6
it works and my output does show the result. I guess you didn't save the file after making the changes or are running different file
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I'm getting a NameError: ...not defined. vonArre 2 154 Mar-24-2024, 10:25 PM
Last Post: vonArre
  Getting NameError for a function that is defined JonWayn 2 1,056 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 2,772 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  [split] NameError: name 'csvwriter' is not defined. Did you mean: 'writer'? cathy12 4 3,199 Sep-01-2022, 07:41 PM
Last Post: deanhystad
  NameError: name ‘app_ctrl’ is not defined 3lnyn0 0 1,457 Jul-04-2022, 08:08 PM
Last Post: 3lnyn0
  User-defined function to reset variables? Mark17 3 1,588 May-25-2022, 07:22 PM
Last Post: Gribouillis
  NameError: name 'hash_value_x_t' is not defined Anldra12 5 1,863 May-13-2022, 03:37 PM
Last Post: deanhystad
  NameError: name 'cross_validation' is not defined tmhsa 6 13,179 Jan-17-2022, 09:53 PM
Last Post: TropicalHeat
  NameError: name “x” is not defined ... even though x is defined campjaybellson 7 14,668 Oct-20-2021, 05:39 PM
Last Post: deanhystad
  NameError: name 'Particle' is not defined in Pygame drunkenneo 4 3,298 Aug-15-2021, 06:12 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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