-
Notifications
You must be signed in to change notification settings - Fork 0
Homework Exercise (Day 2)
Your task:
Design a very simple calculator that takes the following input first:
What is your operation? (+,-,*,/): <input here>
Hint #1
As you learnt with conditionals, this is actually really easy. All you have to do is run it through a control flow like this:
if operation == "+": do something
elif operation == "-": do something
elif operation == "*": do something
else: do somethingFollowed by this, it takes the values on the left and right as follows:
What is the first number? : <input here>
What is the second number? : <input here>
Hint #2
If you don't remember how to take inputs and typecasting, the following is representative of what you need to do:
num = float(input("What is your ______ number? : "))Then print out the output:
The output of this operation is <output here>.
Hint #3
How do we add a "." right after the output?
Basically, you need the typecast the output to str.
Essentially:
print("The output of this operation is", str(output)+".")Note: the numbers should support up till decimal point numbers. If you want to try further, try implementing this same feature for complex numbers.
Ideal case:
What is your operation? (+,-,*,/): +
What is the first number? : 5
What is the second number? : 3
The output of this operation is 8.
By a team of students from NUS High School, aiming to make coding easier for everyone.