>>>
Bitte gebe die Rechnung ein: 5 * 6
Traceback (most recent call last):
File "C:\Dokumente und Einstellungen\Krauzi\Desktop\rechner.py", line 45, in <module>
ZAHL1 = int(EINGABE[0])
ValueError: invalid literal for int() with base 10: '5 * 6'
>>>
Die Python-Datei:
Code: Alles auswählen
#Variablen
WIEDERHOLUNG = True
#Rechnen
def Rechne(Zahl1, Zahl2, Rechenart):
if Rechenart == '+':
Ergebnis = Zahl1 + Zahl2
elif Rechenart == '-':
Ergebnis = Zahl1 - Zahl2
elif Rechenart == '*':
Ergebnis = Zahl1 * Zahl2
else:
Ergebnis = Zahl1 / Zahl2
return Ergebnis
#Eingabe und Eingabefilterung
while WIEDERHOLUNG:
EINGABE = raw_input("Bitte gebe die Rechnung ein: ")
if EINGABE.find('+'):
EINGABE = EINGABE.split('+')
RECHENART = '+'
elif EINGABE.find('-') == 0:
EINGABE = EINGABE.split('-')
RECHENART = '-'
elif EINGABE.find('*') == 0:
EINGABE = EINGABE.split('*')
RECHENART = '*'
elif EINGABE.find('x') == 0:
EINGABE = EINGABE.split('x')
RECHENART = '*'
elif EINGABE.find('/') == 0:
EINGABE.split('/')
RECHENART = '/'
else:
EINGABE.split(':')
RECHENART = '/'
ZAHL1 = int(EINGABE[0])
ZAHL2 = int(EINGABE[1])
print "Das Ergebnis lautet:", Rechne(ZAHL1, ZAHL2, RECHENART)