Wenn ich den Code ausführen und ausführen, scheint das Programm den c-Eingang nicht zu speichern, daher wird der Code nicht fortgesetzt, um den Rest der Rechnerfunktion auszuführen.Warum funktioniert mein Python-Rechner nicht?
def calc():
print("Press 1 for addition")
print("Press 2 for subtraction")
print("Press 3 for multiplication")
print("Press 4 for division")
c = input()
if c == 1:
print("Enter a number")
x = input()
print("Enter another number")
y = input()
return x + y
elif c == 2:
print("Enter a number")
x = input()
print("Enter another number")
y = input()
return x - y
elif c == 3:
print("Enter a number")
x = input()
print("Enter another number")
y = input()
return x * y
elif c == 4:
print("Enter a number")
x = input()
print("Enter another number")
y = input()
return x/y
calc()
Ich habe verbessert jetzt den Code aber kann nicht scheinen, um den Einzug richtig zu machen, und es scheint, dass die Rückkehr-Funktion auf jede Art von Mathematik, die ‚außerhalb Funktion‘ ist
ausgeführt wirddef calc():
print("Press 1 for addition")
print("Press 2 for subtraction")
print("Press 3 for multiplication")
print("Press 4 for division")
c = int(input())
def get_inputs():
print("Enter a number")
x = int(input())
print("Enter another number")
y = int(input())
return x, y
if c == 1:
x, y = get_inputs()
return x + y #These return functions seem to be an error
elif c == 2:
x, y = get_inputs()
return x - y
elif c == 3:
x, y = get_inputs()
return x * y
elif c == 4:
x, y = get_inputs()
return x/y
calc()
'Eingang()' gibt eine Zeichenfolge in Python 3; Sie wollen eine ganze Zahl 'c = int (Eingabe())' –
Was ist das Problem? – harshil9968