Need Help With Specific Error

For students who are taking a programming course, may be restricted in what they can use, or have other unusual limitations on solving their task.

Need Help With Specific Error

Postby I3G » Wed Sep 28, 2016 1:50 am

Hello Everyone,

I think it is a very simple fix, but I have worked on it for a couple hours now and do not know what I am doing wrong. When I enter in the speed over 100 it prompts "is it your birthday?", if yes, then "you do not get a ticket", if no, then it prompts you with a $500 dollar ticket message.

I do not know why my program error messages when speed is less than or equal to 100. The error is the following:
"What speed were you travelling? 56
you were driving 6 KM over the 50 KM speed limit.
your fine is $57
Traceback (most recent call last):
File "C:\Users\richa\Desktop\CMPT 101\Lab\L3Q2RN New Copy.py", line 27, in <module>
if(birthdayY == "yes"):
builtins.NameError: name 'birthdayY' is not defined"


I would like the code to prompt for birthday question only when the speed is greater than or equal to 101. [removed]

Thank you,
I3G
Last edited by micseydel on Wed Sep 28, 2016 1:57 am, edited 2 times in total.
Reason: Initial post lock. Removed PM request.
I3G
 
Posts: 3
Joined: Wed Sep 28, 2016 1:39 am

Re: Need Help With Specific Error

Postby micseydel » Wed Sep 28, 2016 1:58 am

The point of this forum is public education, so we don't help over PMs. If you're concerned with copiers, then you can take unusual care reducing your code to the minimum possible to reproduce the question, so that it's more about your subtask than the homework assignment. But we definitely need to see some code.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Need Help With Specific Error

Postby I3G » Wed Sep 28, 2016 2:05 am

Portion of Code is posted below:

Code: Select all
speed = int(input("What speed were you travelling? "))
if(
speed >= 66 and speed < 86):
    speed = (speed - 50)
    print("you were driving", speed, "KM over the 50 km speed limit.")
    print("your fine is $103")
if(
speed >= 86 and speed <= 100):
    speed = (speed - 50)
    print("you were driving", speed, "KM over the 50 km speed limit.")
    print("your fine is $174")
if(
speed > 100):
    birthdayY = input("Is it your birthday (yes or no)? ")
    birthdayY = birthdayY.lower()
if(
birthdayY == "yes"):
    if("yes"):
        print("you do not get a ticket")
else:
    speed = (speed - 50)
    print("you were driving", speed, "KM over the 50 speed limit.")
    print("your fine is $500")
Last edited by micseydel on Wed Sep 28, 2016 4:05 am, edited 1 time in total.
Reason: Code tags.
I3G
 
Posts: 3
Joined: Wed Sep 28, 2016 1:39 am

Re: Need Help With Specific Error

Postby buran » Wed Sep 28, 2016 4:06 am

Use [CODE] tags around your code. This will preserve the indentation.
We are moving to http://www.python-forum.io as of 1 October. Did you register there?
buran
 
Posts: 372
Joined: Tue Apr 08, 2014 4:53 pm
Location: Bulgaria, EU

Re: Need Help With Specific Error

Postby micseydel » Wed Sep 28, 2016 4:10 am

Your problem can actually be demonstrated with even fewer lines of code
Code: Select all
speed = int(input("What speed were you travelling? "))
if(
speed > 100):
    birthdayY = input("Is it your birthday (yes or no)? ")
    birthdayY = birthdayY.lower()
if(
birthdayY == "yes"):
    if("yes"):
        print("you do not get a ticket")

For an input with speed less than or equal to 100, the variable will not be defined. The solution to this is to either initialize it to no, or to simply indent the second if within the first. Also, the third one can (and should be) left out entirely.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Need Help With Specific Error

Postby I3G » Wed Sep 28, 2016 4:15 pm

Thank you for the help! Got the problem going as it is supposed to =). Best wishes.
I3G
 
Posts: 3
Joined: Wed Sep 28, 2016 1:39 am


Return to Homework

Who is online

Users browsing this forum: No registered users and 4 guests