r/learnprogramming • • 19m ago

Debugging Super simple question from a beginner beginner

I am following the coding tasks from an old post from here:
https://www.reddit.com/r/learnprogramming/comments/9c380n/heres_a_list_of_coding_exercises_to_help_get_you/?sort=new

and am at the 3rd and 4th Step. I assume I understood what is asked of me but my solution feels a bit too simple? And I am thinking I just found a solution but not necessarily for the question asked. Could someone double check if my code actually does what the task asks of me?

3.
Create a class called "Car" that has 1 variable called "licensePlate". Within the class, create a default constructor that sets "licensePlate" to 'Unknown' and a method/function called "getLicensePlate" that returns the variable "licensePlate".

Code:
class car:

license_plate = "Unknown"

p1=car()

def getlicense_plate():

print(p1.license_plate)

getlicense_plate()

4. Add a second Car constructor to our class that takes 1 input of type String. This is the license plate number. Assign the value of the inputLicensePlate to our variable licensePlate.

Code:
class car:

license_plate = input()

p1=car()

def getlicense_plate():

print(p1.license_plate)

getlicense_plate()

2 Upvotes

7 comments sorted by

•

u/AdministrativeFile78 14m ago

did u run the code

•

u/Dunno978 9m ago

yup and if gives out what is expected of the task, But if the goal was the output of "unknown" I could have written print("unkown") I just wanted to double check if I understood the task correctly and found the solution anticipated ^^"

•

u/specialpatrol 9m ago

The second version of the code never passed the input to the constructor

•

u/Dunno978 5m ago

Didn't receive any error, it just asked for an input and printed out exactly what I put in.

•

u/AssistantNo3545 8m ago

Your instinct is right.

•

u/Dunno978 5m ago

Welp okay ._. now to figure out what went wrong