Je suis un débutant en train d'apprendre Python, et j'ai exécuté quelque chose de similaire à ce code et cela a bien fonctionné. Puis j'ai fait quelques changements (comme au lieu de simplement avoir une fonction multiplier, j'ai créé les fonctions multiply_two et multiply_three) et je l'ai exécuté à nouveau, mais je continue d'avoir une Erreur de syntaxe sur total_hours_worked = float (... et les deux autres juste en dessous . Je ne peux pas comprendre ce que je fait de mal apprécié Tout conseilPython 2.7 erreur de syntaxe invalide
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
Merci, qui a fixé le! Je n'ai pas remarqué ça. – pez