mark=input("Please enter the mark you received for the test:")
total=input("Please enter the mark the test was out of:")
percentage=(mark*100/total)
print("Your percentage is:"),percentage,"%"
Lorsque j'exécute ceci dans python 3.3.2 mac il arrive avec cette erreur.Pourcentages Calculs ne fonctionnant pas
Traceback (most recent call last):
File "/Users/user1/Desktop/Percentage2.py", line 4, in <module>
percentage=(mark/total*100)
TypeError: unsupported operand type(s) for /: 'str' and 'str'
Comment puis-je résoudre le problème?
Aucun expert sur Python, mais l'erreur indique clairement que vous ne pouvez pas utiliser de chaîne dans un calcul mathématique. Changez vos variables en type numérique ou convertissez-les en type numérique. –