J'ai un code python qui échoue:essai: déclaration échoue
import sys
print ("MathCheats Times-Ed by jtl999")
numbermodechoice = raw_input ("Are you using a number with a decimal? yes/no ")
if numbermodechoice == "yes":
try:
numberx1 = float(raw_input('Enter first number: '))
except ValueError:
print ("Oops you typed it wrong")
try:
numberx1 = float(raw_input('Enter first number: '))
except ValueError:
print ("Oops you typed it wrong")
numberx2 = (float)(raw_input('Enter second number: '))
elif numbermodechoice == "no":
print ("Rember only numbers are allowed")
numberx1 = (int)(raw_input('Enter first number: '))
numberx2 = (int)(raw_input('Enter second number: '))
else:
print ("Oops you typed it wrong")
exit()
print ("The answer was")
print numberx1*numberx2
ostype = sys.platform
if ostype == 'win32':
raw_input ("Press enter to exit")
elif ostype == 'win64':
raw_input ("Press enter to exit")
(code complet here)
Je veux envelopper les opérations de flotteur avec instructions try donc si un ValueError
arrive, il est pris . Voici la sortie:
File "./Timesed.py", line 23 try: ^ IndentationError: expected an indented block
Quel est le problème et comment puis-je résoudre ce problème?
@Senthil: Il ne permet pas si vous corrigez le code qui a des problèmes en elle. –
@ S.Lott Parce que ce nouvel utilisateur essaie probablement d'apprendre Python, et fait probablement beaucoup d'erreurs. –
Vous devez fournir l'indentation exacte pour chaque ligne. Remplacez tous les caractères de tabulation par 8 espaces et reproduisez le fichier exact. vous pouvez lancer python -tt sur le script [si vous sauvegardez le texte dans un script] et il vous dira si vous avez indenté correctement –