它给了我同样的错误,我不知道如何修复它:
Traceback (most recent call last):
File "/tmp/sessions/b41f205e56036d7a/main.py", line 20, in <module>
car.append
AttributeError: 'str' object has no attribute 'append'
while True:
car = input("Choose one of the car brands we have recommended.")
if car.lower() == "q":
break
else:
price = float(input(f"Write a price for the brand of cars from those we have offered you in order to choose which car from these brands to offer you. {car}: $"))
car.append(car)
price.append(price)
print("----- YOUR CARS -----")
for car in car:
print(car)
您使用的变量 car 是一个字符串,因此它没有追加方法。您需要创建其他变量来存储汽车和价格。 EG
car_list = []
price_list = []
while True:
car = input("Choose one of the car brands we have recommended.")
if car.lower() == "q":
break
else:
price = float(input(f"Write a price for the brand of cars from those we have offered you in order to choose which car from these brands to offer you. {car}: $"))
car_list.append(car)
price_list.append(price)
print("----- YOUR CARS -----")
for car in car_list:
print(car)