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: name 'pins' is not defined glennford49 2 385 Jun-15-2020, 12:20 PM
Last Post: glennford49
  python library not defined in user defined function johnEmScott 2 152 May-30-2020, 04:14 AM
Last Post: DT2000
  [split] NameError: name 'formats' is not defined shobhu123 1 324 May-24-2020, 06:29 PM
Last Post: Skaperen
  NameError: name 'cross_validation' is not defined tmhsa 5 870 Apr-21-2020, 08:15 PM
Last Post: DT2000
  NameError: name 'os' is not defined lrpirlet 6 1,043 Apr-01-2020, 08:43 PM
Last Post: buran
  NameError: name 'edit' is not defined CabbageMan 5 625 Dec-17-2019, 04:48 PM
Last Post: CabbageMan
  NameError 'odometer' not defined rfernandez15 1 419 Nov-25-2019, 09:57 PM
Last Post: ichabod801
  NameError: NameError: global name 'BPLInstruction' is not defined colt 7 749 Oct-27-2019, 07:49 AM
Last Post: Larz60+
  Function Annotation got NameError: name 'xxx' is not defined Lance 6 940 Oct-23-2019, 03:13 AM
Last Post: Lance
  NameError: name 'processing' is not defined soli004 2 1,062 Sep-07-2019, 11:57 AM
Last Post: soli004

Forum Jump:


Users browsing this thread: 1 Guest(s)