#Variables
total = 0
day = 0
car = 0
while day <= 4:
day += 1
if day <= 5:
print('Cars sold on day', day, end = ': ',)
carSold = int(input(''))
for amount in range(carSold):
print('Selling price of car', amount + 1, end = ':\t')
price = int(input('$'))
if day >= 5:
total += price
car += carSold
print('\nYou sold', car, 'cars for a total of $', format(total,',.2f'))
我尝试过的不同配置要么在每次输入后添加,要么只添加最后一个值
编辑时间: 在Python中,编写简洁的代码非常重要,错误检查也非常重要,因为键入数字以外的任何内容都很容易产生错误:
您只在最后一天向
total
和car
添加了值,而下面的代码每天都在添加值相关问题 更多 >
编程相关推荐