Мой цикл while не обновляет мою новую комиссию продаж eveerytime. Я запускаю программу. Вот моя программа:Программа комиссии продаж, использующая цикл while. Значение не обновляется
#this program calculates sales commissions and sums the total of all sales commissions the user has entered
print("Welcom to the program sales commission loop")
keep_going='y'
while keep_going=='y':
#get a salespersons sales and commission rate
sales=float(input('Enter the amount of sales'))
comm_rate=float(input('Enter commission rate'))
total=0
#calculate the commission
commission=sales*comm_rate
print("commission is",commission)
keep_going=input('Enter y for yes')
total=total+commission
print("Total is",total)
print("You have exited the program. Thet total is",total)
Вот вывод программы: Python 3.5.2 (v3.5.2: 4def2a2901a5, 25 Июнь 2016, 22:01:18) [MSC v.1900 32 бит (Intel)] on win32 Тип «авторское право», «кредиты» или «лицензия()» для получения дополнительной информации.
Welcom to the program sales commission loop
Enter the amount of sales899
Enter commission rate.09
commission is 80.91
Enter y for yesy
Total is 80.91
Enter the amount of sales933
Enter commission rate.04
commission is 37.32
Enter y for yesy
Total is 37.32
Enter the amount of sales9909
Enter commission rate.10
commission is 990.9000000000001
Enter y for yesn
Total is 990.9000000000001
You have exited the program. Thet total is 990.9000000000001
>>>
> Blockquote
Что я делаю неправильно? Я не могу понять это
Как вы думаете, что получилось не так? Убедитесь, что вы записываете ожидаемый ввод и вывод, потому что это не всегда явно. – Nishant
, если вы имеете в виду общее не обновляя его, потому что вы устанавливаете его в 0 в начале каждого цикла. переместить total = 0 за пределы цикла, как раз перед его запуском – wbrugato
Лучше было бы сделать: «keep_going = True», а затем «while keep_going». Если вы хотите использовать код «=», тогда вы должны сказать «while» y в keep_going. – JasonD