-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathsimple_calculator_challenge.py
171 lines (73 loc) · 3.65 KB
/
simple_calculator_challenge.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# --------------------------------------------
# You've just learned all about functions.
# Now take what you've learned to create your own
# CALCULATOR!
# We'll guide you through the first few steps,
# then you'll have a chance to add your own features
# that will make this your new go-to calculator!
# --------------------------------------------
print("My Simple Calculator")
# --------------------------------------------
# Part 1:
# The first features of any simple calculator is that
# it should be able to perform the basic math operations.
# Let's start by writing the functions we'll need to execute
# the following operations:
# Addition
# Subtraction
# --------------------------------------------
# Write a function called add_numbers that will take two numbers and return the sum.
# Write a function called sub_numbers that will take two numbers and return the difference.
# ------------
# Testing Code - Uncomment the code below to test your code!
# check_answers(add_numbers(5, 15), 20)
# check_answers(add_numbers(3, 18), 21)
# check_answers(add_numbers(12, 28), 40)
# check_answers(sub_numbers(18, 7), 11)
# check_answers(sub_numbers(11, 9), 2)
# check_answers(sub_numbers(18, 21), -3)
# --------------------------------------------
# Part 2:
# Now that you have addition and subtraction down, let's add the other operators we learned!
# Finish off your basic calculator by writing the functions
# for the following operations:
# Multiplication
# Division
# --------------------------------------------
# Write a function called multiply_numbers that will take two numbers and return the product.
# Write a function called divide_numbers that will take two numbers and return the quotient.
# ------------
# Testing Code - Uncomment the code below to test your code!
# check_answers(multiply_numbers(10, 3), 30);
# check_answers(multiply_numbers(21, 7), 147);
# check_answers(multiply_numbers(4, 16), 64);
# check_answers(divide_numbers(24, 100), `.24`);
# check_answers(divide_numbers(21, 7), `3`);
# check_answers(divide_numbers(15, 4), `3.75`);
# --------------------------------------------
# Part 3:
# Now that you have your basic functions in place, you need to get some user input.
# What's a calculator for if no one is using it?
# Write a function that will prompt the user for the operation they want to call and the values they are inputting.
# --------------------------------------------
# --------------------------------------------
# Part 4:
# Now that you have all of the basic four operations completed, you get to add your own features!
# What will you add to make this your go-to calculator?
# Stuck? : Think about what you count/calculate on a (almost) daily basis.
# Can you write a function that will take in the data you need and do the calculation for you?
# (I know I calculate how many hours of sleep I get every day... 。(*^▽^*)ゞ )
# --------------------------------------------
# Write a function or functions that will add some unique features to your calculator.
# Don't forget to:
# Give your function an name and parameters that are self explanatory and written in camelcase!
# Use comments throughout your code
# Test your code!
# --------------------------------------------
# --------------------------------------------
# Ignore this section. This is just for checking your work
def check_answers(gen_answer, correct_answer):
if gen_answer == correct_answer:
print("Your code works!")
else:
print(f"Try again, your code generated {gen_answer} but the correct answer is {correct_answer}")