2014-04-24 155 views
-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 

回答

4

你错过了一个括号“)”在行的末尾:。

 
bonus = float(raw_input("What is your yearly bonus amount, in dollars?\n ") 
+0

谢谢,定了!我没有注意到这一点。 – pez