Laden...

Taschenrechner-Problem in Python

Letzter Beitrag vor 8 Monaten 5 Posts 377 Views
Taschenrechner-Problem in Python

Also ich habe ein kleines script für einen komischen Taschenrechner geschrieben und der if - if -if -if teil unten wird einfach übersehen.

Ich brauche eure hilfe beim Programmieren ( Phyton). Bitte.

Mein Script:

one = int(input("1 zahl: "))
two = int(input("2 Zahl: "))
tree = int(input("3 Zahl: "))
four = int(input("4 Zahl: "))

def add():
val = one + two + tree + four
return val

def sub():
val = one - two - tree - four
return val

def multiply():
val = one * two * tree * four
return val

def div():
val = one / two / tree / four
return val

x = input('''Was wollen sie rechnen?
+ = 1
- = 2
* = 3
/ = 4
:   ''')

if x == 1:
print(multiply)
if x == 2:
print(sub)
if x == 3:
print(multiply)
if x == 4:
print(div)

Ich habe es noch ein bisschen geendert und es ist das rausgekommen (anderung : int(input(...)).

Script:

one = int(input("1 zahl: "))
two = int(input("2 Zahl: "))
tree = int(input("3 Zahl: "))
four = int(input("4 Zahl: "))

def add():
val = one + two + tree + four
return val

def sub():
val = one - two - tree - four
return val

def multiply():
val = one * two * tree * four
return val

def div():
val = one / two / tree / four
return val

x = int(input('''Was wollen sie rechnen?
+ = 1
- = 2
* = 3
/ = 4
:   '''))

if x == 1:
print(multiply)
if x == 2:
print(sub)
if x == 3:
print(multiply)
if x == 4:
print(div)

Kenn mich mit Python null aus, aber müsste es nicht lauten:

if x == 1:
    print(multiply())
if x == 2:
    print(sub())
if x == 3:
    print(multiply())
if x == 4:
    print(div())

Es ist nicht if if if... sondern if elif ... else. Aber Danke die 2 Klammern haben gefehlt.

@Sprintown
Besser wäre switch case zu nehmen.

Link:
https://www.freecodecamp.org/news/python-switch-statement-switch-case-example/

T-Virus

Developer, Developer, Developer, Developer....

99 little bugs in the code, 99 little bugs. Take one down, patch it around, 117 little bugs in the code.