[Python] how to code a python calculator

Discussão em 'Python' iniciado por Stack, Julho 4, 2025.

  1. Stack

    Stack Membro Participativo

    I want to code a python calculator, but it goes wrong. Okay, I'll show you my code.

    from time import sleep
    print('Calculator v1.0 (Python 3.6.2)')
    ans = input('Hello! Are you here for calculating?(y/n)')
    if ans == 'y':
    print('OK! LOADING...')
    sleep(3)
    elif ans == 'n':
    print('Oh, you're not going ahead... OK.')
    quit()

    num1 = input('Input 1st number')
    method = input('Input symbol(+,-,*,/):')
    num2 = input('Input 2nd number')
    ans = num1+method+num2
    print('Answer is ', ans)


    And my output....

    Calculator v1.0 (Python 3.6.2)
    Hello! Are you here for calculating?(y/n)y
    OK! LOADING...
    Input 1st number1
    Input symbol(+,-,*,/):+
    Input 2nd number1
    Answer is 1+1.


    I want this output:

    Calculator v1.0 (Python 3.6.2)
    Hello! Are you here for calculating?(y/n)y
    OK! LOADING...
    Input 1st number1
    Input symbol(+,-,*,/):+
    Input 2nd number1
    Answer is 2


    Somebody HELP!!!!!!!!!

    Continue reading...

Compartilhe esta Página