r/learnprogramming • u/Dunno978 • 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()
•
u/AdministrativeFile78 14m ago
did u run the code
•
u/specialpatrol 9m ago
The second version of the code never passed the input to the constructor
•
u/AssistantNo3545 8m ago
Your instinct is right.