Question

With the use of if statements, create a Calculator program that only uses 1 input. For...

With the use of if statements, create a Calculator program that only uses 1 input.

For example, if a person inputs 2 + 3, the program should print 5.

If the person inputs 3 - 1, the program should return 2.

If the person input 4 / 2, the program should return 2.

If the person inputs 3 * 2, the program should return 6.

Python

0 0
Add a comment Improve this question Transcribed image text
Answer #1
expression = input("Enter a simple expression: ")
n1 = float(expression.split()[0].strip())
n2 = float(expression.split()[2].strip())
ch = expression.split()[1].strip()

print(expression + " = ", end='')
if ch == '+':
    print(n1 + n2)
elif ch == '-':
    print(n1 - n2)
elif ch == '*':
    print(n1 * n2)
elif ch == '/':
    print(n1 / n2)
elif ch == '%':
    print(n1 % n2)
elif ch == '**':
    print(n1 ** n2)
else:
    print('Unknown')




Add a comment
Know the answer?
Add Answer to:
With the use of if statements, create a Calculator program that only uses 1 input. For...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a single program in java using only do/while loops for counters(do not use array pls)...

    Write a single program in java using only do/while loops for counters(do not use array pls) for the majority of the program and that asks a user to enter a integer and also asks if you have any more input (yes or no) after each input if yes cycle again, if not the program must do all the following 4 things at the end of the program once the user is finished inputting all inputs... a.The smallest and largest of...

  • In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while...

    In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while loop or a for loop to print only odd numbers 1, 3, 5, 7, 9 *tip: you can use range () function, or a condition with ‘break’ (e.g, while count < 10) In python!: Create a program that print out 12 months of a year and associated numbers (e.g., January 1, February 2…). Two lists should be created, and then loop through the list...

  • # Write PYTHON programs that read a sequence of integer inputs and print # a.  The...

    # Write PYTHON programs that read a sequence of integer inputs and print # a.  The smallest and largest of the inputs. # b.  The number of even and odd inputs. # c.  Cumulative totals. For example, if the input is 1 7 2 9, the program should print # 1 8 10 19. # d.  All adjacent duplicates. For example, if the input is 1 3 3 4 5 5 6 6 6 2, the # program should print...

  • Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an...

    Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an integer. Once the input is stored, use an if-else-if block of code to determine the letter grade of the inputted integer grade. Do not use a bunch of if statements by themselves to solve this problem. You will print an error message for inputs greater than 100 and for inputs less than 0. Both errors must be...

  • create a python program that requests input from the user for a starting and ending value....

    create a python program that requests input from the user for a starting and ending value. then your program should return all prime numbers between those two values. you will be using input, conditional and control flow statements

  • 3. Write Python statements that will do the following: a) Input a string from the user....

    3. Write Python statements that will do the following: a) Input a string from the user. *** Print meaningful messages along with your output.* b) Print the length of the String. Example input: The sky is blue. Correct output: The length of the string is 16 Incorrect output: 16 c) Print the first character of the string. d) Print the last character of the string. 4. Save the program. Double-check the left edge for syntax errors or warning symbols before...

  • C++ program Please only (if) (else) statements No while statements use Write a program that takes...

    C++ program Please only (if) (else) statements No while statements use Write a program that takes rate and outputs the employee's wages for the week input employee's hours worked and regular pay as an Calculate employee's wages as follows: She receives her regular rate for the an first 40 hours, 1.5 times her regular rate for each hour between 40 and 50 hours, and double her regular rate for each hour over 50. For invalid inputs, in addition to outputting...

  • This program will require you to create a basic parser for an input string that is...

    This program will require you to create a basic parser for an input string that is somewhat like Python. Python has an older parser module and a newer ast module to manage pure Python syntax, but they won't be useful here. The program will read a data string, identify the control characters, and print out the overall structure of the string. Here's an example Input String: [{1}] Output: Number inside a dictionary inside a list Here are some basic rules...

  • PYTHON Programming Exercise 2: Create a Simple Cost Calculator Write a program that displays input fields...

    PYTHON Programming Exercise 2: Create a Simple Cost Calculator Write a program that displays input fields (item name and cost) and calculates and displays the calculated costs. The program should do the following: Provide data entry areas for item name and cost. Calculate and display the subtotal of all items. Adds a sales tax of 6% and calculate and displays the total cost. Enter the following values into your program. Mother Board $200. RAM $75. Hard Drive $72. Video Graphics...

  • Use a switch statement to build a menu-driven calculator

    ENGR 40 PROGRAMMING ASSIGNMENT MENU-DRIVEN CALCULATOR PROGRAM Use a switch statement to build a menu-driven calculator. Your program should ask the user to choose from a list of ten possible functions (square root, square, natural log, common log, e'x yx, 1/x, sin(x), cos(x), and tan(x). Each choice will correspond to an integer -example: (1) square root, (2) square, etec. Once the person has input a function choice then a switch statement will control the flow of the program- ie. the program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT