-1
我是一名初學者學習Python,我運行了類似於這段代碼的東西,它工作正常。然後我做了一些改變(比如不是隻有一個乘法函數,而是創建了multiply_two和multiply_three函數)並再次運行它,但是我總是在total_hours_worked = float(...)和其他兩個正確的位置我想不出我做錯任何意見讚賞Python 2.7無效的語法錯誤
def multiply_two(a, b):
print "Multiplying %d and %d to get annual earnings." % (a, b)
return a * b
def multiply_three(a, b, c):
print "Multiplying %d, %d, and %d to get total hours worked per year." % (a, b, c)
return a * b * c
def add(a, b):
print "Adding %d and %d to get total annual compensation." % (a, b)
return a + b
hours_worked = float(raw_input("How many hours per day do you work?\n> "))
days_worked = float(raw_input("How many days per week do you work?\n> "))
weeks_worked = float(raw_input("How many weeks per year do you work?\n> "))
wage = float(raw_input("What is your hourly wage?\n> "))
bonus = float(raw_input("What is your yearly bonus amount, in dollars?\n ")
total_hours_worked = float(multiply_three(hours_worked, days_worked, weeks_worked))
annual_earnings = float(multiply_two(total_hours_worked, wage))
total_annual_compensation = float(add(annual_earnings, bonus))
print "\nYour total hours worked per year are %r." % total_hours_worked
print "Your annual earnings are $%r." % annual_earnings
print "Your total annual compensation is $%r." % total_annual_compensation
謝謝,定了!我沒有注意到這一點。 – pez