Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Python, create a program that will act as a calculator. 1) This calculator will ask the user whether they would like to add, subtract,

image text in transcribed
Using Python, create a program that will act as a calculator. 1) This calculator will ask the user whether they would like to add, subtract, multiply, divide, or raise (exponents) two floats. Also, the option to find sum of first n Natural Numbers. You can use (i) symbol for natural sum. You should provide the user with the detailed option. [5\% marks]. 2) The user should be able to type either the word or respective operator, (i.e., if they would like to add two numbers, theycan enter either write "add" or " + "). No need to check all lowercase/uppercase. You just need to change the input to uppercase using (upper). [10\% marks] 3) After choosing the desired mathematical operation, the program should then ask the user to input two numbers one by one. From there, the program should compute the two numbers in the requested method, store the value in a variable, and print out the result, [15\% marks] 4) The program should loop indefinitely, allowing the user to perform another mathematical operation unless user types"exit" or "stop". Hint: You can use infinite while loop here. [10\% marks] 5) If at any point the user only enters one number and does not enter anything in another number field, that number will be computed with the result of the previous operation. Hint: if you add two numbers together and then later choose subtraction, entering only a single number will subtract it from the previously added numbers. Say, the sum of previous numbers is 20 and if you enter subtract, then enter num 1=10 (or num 2=10 ) and enter nothing in num2 (or num1) field, the result will be computed as 2010=10. No need to write a condition where both numbers are not entered. [20\% marks] 6) For the exponential option, do NOT use " or pow operator from math library. Hint: Implement this by applying logicusing a while or for loop. [15\% marks]. If you directly use "* or pow operator for exponent, NO marks will be allotted. 7) For "Sum of first n Natural Numbers", Use for loop to find the sum from 1 up to the entered numbers. For example, if user inputs 3 , the sum would be 1+2+3=6. You should do this operation for both numbers. [15\% marks]. 8) If at any point the user enters the word "stop" or "exit", the program should terminate. [10\% marks]. Hint: You should implement this logio for every input. For example, if user enters an operation "add", then changes his/her mind and wants to exit the program. This user should be allowed to exit at any point by inputting "exit" or "stop" command. Or if the userhas entered the operation and num1, now wants to exit without entering num2, this should be allowed. Or after completing one operation on two numbers and getting the result, user should be allowed to exit. In summary, make sure that user can exit the program whenever helshe wants to without the program throwing any errors

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions