Это неправильное использование короткого замыкания. Не используйте and
таким образом. Используйте if
операторы.
Для двух десятичных знаков ставьте 2
после десятичного знака: %.2f
, а не %2.f
.
if DidHourPlus == 1 and StartWeek == 1 and post == "r": print("The daily salary is %.2f" % ((hours - 8) * 35 + 8 * 30)))
if DidHourPlus == 1 and StartWeek == 1 and post == "s": print("The daily salary is %.2f" % (1.20*((hours - 8) * 35 + 8 * 30)))
if DidHourPlus == 1 and StartWeek == 1 and post == "m": print("The daily salary is %.2f" % (1.50*((hours - 8) * 35 + 8 * 30)))
Вы можете извлечь повторные тесты в один if
:
if DidHourPlus == 1 and StartWeek == 1:
if post == "r": print("The daily salary is %.2f" % ((hours - 8) * 35 + 8 * 30)))
if post == "s": print("The daily salary is %.2f" % (1.20*((hours - 8) * 35 + 8 * 30)))
if post == "m": print("The daily salary is %.2f" % (1.50*((hours - 8) * 35 + 8 * 30)))
Затем извлечь распечатку:
if DidHourPlus == 1 and StartWeek == 1:
salary = None
if post == "r": salary = (hours - 8) * 35 + 8 * 30
if post == "s": salary = 1.20*((hours - 8) * 35 + 8 * 30)
if post == "m": salary = 1.50*((hours - 8) * 35 + 8 * 30)
if salary:
print("The daily salary is %.2f" % salary)
Затем извлечь расчет зарплаты:
if DidHourPlus == 1 and StartWeek == 1:
rate = None
if post == "r": rate = 1.00
if post == "s": rate = 1.20
if post == "m": rate = 1.50
if rate:
salary = rate * ((hours - 8) * 35 + 8 * 30)
print("The daily salary is %.2f" % salary)
Вы можете остановиться на этом, но если вы хотите стать еще интереснее, вы можете посмотреть цены в словаре.
if DidHourPlus == 1 and StartWeek == 1:
rates = {"r": 1.00, "s": 1.20, "m": 1.50}
rate = rates.get(post)
if rate:
salary = rate * ((hours - 8) * 35 + 8 * 30)
print("The daily salary is %.2f" % salary)
В Python 3.8 вы можете даже увеличить егодалее с выражением присваивания .
if DidHourPlus == 1 and StartWeek == 1:
rates = {"r": 1.00, "s": 1.20, "m": 1.50}
if rate := rates.get(post):
salary = rate * ((hours - 8) * 35 + 8 * 30)
print("The daily salary is %.2f" % salary)