Bottom Page

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
Quote
#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
Quote
#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}")
Quote
#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
Quote
#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
Quote
#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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  NameError 'odometer' not defined rfernandez15 1 81 Nov-25-2019, 09:57 PM
Last Post: ichabod801
  NameError: NameError: global name 'BPLInstruction' is not defined colt 7 340 Oct-27-2019, 07:49 AM
Last Post: Larz60+
  Function Annotation got NameError: name 'xxx' is not defined Lance 6 299 Oct-23-2019, 03:13 AM
Last Post: Lance
  NameError: name 'processing' is not defined soli004 2 424 Sep-07-2019, 11:57 AM
Last Post: soli004
  NameError: name 'display' is not defined when running code on power bi beginner1 2 1,657 Jul-24-2019, 11:03 AM
Last Post: beginner1
  tkinter - "NameError: name 'frame' is not defined" Mocap 3 1,095 Jul-21-2019, 09:03 PM
Last Post: Yoriz
  [split] NameError: name 'lo' is not defined when using input ? Cedmo 2 430 Jul-05-2019, 09:39 PM
Last Post: Cedmo
  NameError: name 'lst' is not defined Jmekubo 2 829 Apr-27-2019, 12:34 PM
Last Post: Jmekubo
  *** NameError: name '' is not defined adamG 1 886 Apr-08-2019, 01:21 PM
Last Post: ichabod801
  NameError: name 'd' is not defined synthex 1 832 Feb-23-2019, 12:35 PM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)