Skip to content

Homework Exercise (Day 2)

ThePyProgrammer edited this page Jun 23, 2022 · 2 revisions

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 something

Followed 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.

Clone this wiki locally