如果我有这个列表
car=['Mazda','ford','Honda','corvette','Mercedes']
price=['300','450','350','490','500']
我想一次为每个人打印以下句子
print ("that", car,"car price is:",price ,"in thousands dollar")
如何编写我通常使用的条件,但如何为列表执行此操作?
car=input("enter car name:")
price=float(input("price of the car:"))
因为它只会打印我输入的值
car=input("enter car name:")
price=float(input("price of the car:"))
最佳答案
how to do it for a list?
使用zip()
函数:
cars = ['Mazda','ford','Honda','corvette','Mercedes']
prices = ['300','450','350','490','500']
for car, price in zip(cars, prices):
print("that {} car price is: {} in thousands dollar".format(car, price))
输出:
that Mazda car price is: 300 in thousands dollar
that ford car price is: 450 in thousands dollar
that Honda car price is: 350 in thousands dollar
that corvette car price is: 490 in thousands dollar
that Mercedes car price is: 500 in thousands dollar
关于python - 与列表和长度一起使用的 while 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48966738/