Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

why this code no work?

–2 votes
asked May 14, 2021 by ANDON MILLER (150 points)

print ('MathBot: Would you like me to do a math problem?')

if input(': ').lower() == 'no' or 'nope' or 'no thanks' or 'nah' or 'no way dude':

    try:

        print('ok')

        exit()

if input(': ').lower() == 'yes' or 'yeah' or 'yes please' or 'sure' or 'yeah dude':

    try:

        hi = input('/,-,+,x: ')

        num1 = input('number 1: ')

        num2 = input('number 2: ')

        if hi == '+':

            print(float(num1) + float(num2))

    

        if hi == '-':

            print(float(num1) - float(num2))

    

        if hi == '/':

            print(float(num1) / float(num2))

    

        if hi == 'x':

            print(float(num1) * float(num2))

            

    except ValueError:

        print('Error')

1 Answer

+1 vote
answered May 14, 2021 by Nivi (160 points)

print ('MathBot: Would you like me to do a math problem?')
if input(': ').lower() == 'no' or 'nope' or 'no thanks' or 'nah' or 'no way dude':
    print('ok')
    exit()
elif input(': ').lower() == 'yes' or 'yeah' or 'yes please' or 'sure' or 'yeah dude':
    hi = input('/,-,+,x: ')
    num1 = input('number 1: ')
    num2 = input('number 2: ')
    if hi == '+':
        print(float(num1) + float(num2))
    elif hi == '-':
            print(float(num1) - float(num2))
    elif hi == '/':
        print(float(num1) / float(num2))
    elif hi == 'x':
            print(float(num1) * float(num2))

This one works...

commented May 19, 2021 by Elias (120 points)
I can help. Depends what math. I can do addition, subtraction, multiplication, and division but thats it :(
commented May 19, 2021 by Elias (120 points)
I can only do it in C++ though
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...