Ich versuchte, ein Programm in Python zu schreiben, das (wahrscheinlich schrecklich ineffizient, aber ich schweife) mit mehreren verschiedenen Operationen berechnet. Es gab jedoch einen Fehler, den ich beim Ausführen nicht herausfinden kann. Ich denke, es erfordert, den Typ einer Variablen zu definieren. Das Programm:Fehler im Python-Rechner Ich machte
import math
print('Select a number.')
y = input()
print('Select another number.')
x = input()
print('Select what operation you wish to perform. (e for exponentiation, d for division, m for multiplication, a for addition, s for subtraction, mo for modulo, l for log (the base is the first number you entered), r for root)')
z = input()
if z == 'e' or z == 'E':
print('The answer is ' + y**x)
elif z == 'd' or z == 'D':
print('The answer is ' + y/z)
elif z == 'm' or z == 'M':
print('The answer is ' + y*x)
elif z == 'a' or z == 'A':
print('The answer is ' + y+x)
elif z == 's' or z == 'S':
print('The answer is ' + y-x)
elif z == 'mo' or z == 'Mo':
print('The answer is ' + y%x)
elif z == 'l' or z == 'L':
print('The answer is ' + math.log(x,y))
elif z == 'r' or z == 'R':
print('The answer is ' + y**(1/x))
Der Fehler, der in der Schale auftauchten:
Traceback (most recent call last):
File "C:/Users/UserNameOmitted/Downloads/Desktop/Python/Calculator.py", line 7, in <module>
z = input()
File "<string>", line 1, in <module>
NameError: name 'd' is not defined
Verwenden Sie 'raw_input' anstelle von' input'. – Lafexlos
Sind Sie sicher? Diese Zeilennummer ist seltsam - Der Fehler, den ich [online] (https://repl.it/languages/python3) erhalte, ist "Traceback (letzter Aufruf zuletzt): Datei" python ", Zeile 11, in TypeError: nicht unterstützte Operandentypen für /: 'str' und 'str' ". Was schlägt vor, dass dies eine Art von http://stackoverflow.com/questions/24412000/python-type-error-unsupported-operand –
usr2564301