The class Car () :
"" "the program is mainly used to simulate a simple car trying to "" "
Def __init__ (self, the make, model, year) :
"" "initialization describe attributes "" "
Self. Make=make
The self. The model=model
The self. The year=year
Self. Odometer_reading=0
Def get_descriptive_name (self) :
"" "return neat descriptive name "","
Long_name=f "{self. Year} {self. Make} {the self. The model}"
Return long_time. Title ()
Def road_odometer (self) :
"" "to print out a message, and points out that the car mileage "" "
Print (f "This car has {self. Odometer_reading} miles on it.")
Def update_odometer (self, mileage) :
"" "
Set the odometer reading to the specified value,
And refused to let the odometer back,
"" "
If the mileage & gt;=self. Odometer_reading:
Self. Odometer_reading=mileage
The else:
Print (" You can 't roll back an odometer!" )
Def increment_odometer (self, miles) :
"" will increase the amount of specified the odometer reading" "" "
Self. Odometer_reading +=miles
My_new_car=Car (' audi ', 'a4, 2019)
Print (my_new_car. Get_descriptive_name ())
Pycharm and jupter error display:
NameError Traceback (the most recent call last)
2
3 my_new_car=Car (' audi ', 'a4, 2019)
- & gt; 4 the print (my_new_car get_descriptive_name ())
5
~ \ Desktop \ \ data \ in the second week of class car. Py in get_descriptive_name (self)
"" 11" to print out a message, and points out that the car mileage "" "
12 print (f "This car has {self. Odometer_reading} miles on it.")
- & gt; 13
14 def update_odometer (self, mileage) :
15 "" "
NameError: name 'long_time' is not defined
I change long_name="{} {} {}". The format (self. Year, self. Make self. Model) or not,,
Beg big help!!
CodePudding user response:
Def get_descriptive_name (self) :. "" "return neat descriptive name "","
. Long_name=f "{self. Year} {self. Make} {the self. The model}"
. Return long_name. Title ()