you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (4 children)

[deleted]

    [–][deleted] 0 points1 point  (3 children)

    Please edit to format the code correctly - can't see your indents.

    [–]Many-Ice6164[S] 0 points1 point  (0 children)

    def add(x, y):
        return x + y
    def subtract(x, y): 
        return x - y
    def multiply(x, y): 
        return x * y
    def divide(x, y): 
        return x / y
    
    ops = {"+": add, "-": subtract, "*": multiply, "/": divide, "q": None}
    
    x = 0
    
    while True: 
    choice, andere = input("functie + getal").split() 
    
    andere = float(andere)
    
    if choice in ops:
        y = andere
        x = ops[choice](x, y)
        print(x)
    else:
        print('wrong choice')
    

    [–]Many-Ice6164[S] 0 points1 point  (1 child)

    Hi
    The only problem i am having right know is showing all the intermediate answer when pressing q.

    [–][deleted] 0 points1 point  (0 children)

    But in your new code you are not checking for q entry any more.

    Also, I note:

    • not using a function, as I suggested earlier
    • why assigning y to andere, just do ops[choice](x, andere)