-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleCalculator.py
61 lines (56 loc) · 1.95 KB
/
SimpleCalculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
operation = "*"
first_number = 4
second_number = 7
#You may modify the lines of code above, but don't move them!
#When you Submit your code, we'll change these lines to
#assign different values to the variables.
#You're doing your math homework when you realize, you can
#write a program to do all the simple operations!
#
#The five possible values for operation are:
#
# - "+": Add first_number and second_number
# - "-": Subtract second_number from first_number
# - "*": Multiply first_number by second_number
# - "/": FLoor-divide first_number by second_number (use //)
# - "%": Find the remainder of dividing first_number by
# second_number
#
#Your calculator should print the full operation according to
#the following format:
#
#[first_number] [operation] [second_number] = [result]
#
#For example, for the initial values above, your calculator
#would print:
#
#4 * 7 = 28
#
#Notice that for division, we're asking you to use floor
#division to avoid worrying about rounding errors.`
#
##If the operation is not one of the five listed above, print
#"That operation does not exist!"
#Add your code here!
if operation == "+":
total = first_number + second_number
result = (str(first_number) + " + " + str(second_number) + " = " + str(total))
print(result)
elif operation == "-":
total = first_number - second_number
result = (str(first_number) + " - " + str(second_number) + " = " + str(total))
print(result)
elif operation == "*":
total = first_number * second_number
result = (str(first_number) + " * " + str(second_number) + " = " + str(total))
print(result)
elif operation == "/":
total = first_number // second_number
result = (str(first_number) + " / " + str(second_number) + " = " + str(total))
print(result)
elif operation == "%":
total = first_number % second_number
result = (str(first_number) + " % " + str(second_number) + " = " + str(total))
print(result)
else:
print("That operation does not exist!")