-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path021_two_step.py
More file actions
74 lines (50 loc) · 1.47 KB
/
021_two_step.py
File metadata and controls
74 lines (50 loc) · 1.47 KB
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
# Video alternative: https://youtu.be/QoSng0as5BY&t=0s
from lib.helpers import check_that_these_are_equal
# Here's a function:
def add_one_and_divide_by_two_with_statements(num):
added = num + 1
halved = added / 2
return halved
print("add_one_and_divide_by_two_with_statements(5) is:")
print(
add_one_and_divide_by_two_with_statements(5)
)
# You could also do this with a single expression, like this:
def add_one_and_divide_by_two_with_an_expression(num):
return (num + 1) / 2
print("add_one_and_divide_by_two_with_an_expression(5) is:")
print(
add_one_and_divide_by_two_with_an_expression(5)
)
# The statements just break it up a bit more. We'll see some
# more uses for statements and variables soon, but for now
# let's practice using them.
# @TASK: Complete these functions.
# == Exercise One ==
print("")
print("Function: divide_by_two_and_add_one")
def divide_by_two_and_add_one(num):
return num / 2 + 1
check_that_these_are_equal(
divide_by_two_and_add_one(6),
4.0
)
# == Exercise Two ==
print("")
print("Function: multiply_by_forty_and_add_sixty")
def multiply_by_forty_and_add_sixty(num):
return num * 40 + 60
check_that_these_are_equal(
multiply_by_forty_and_add_sixty(3423),
136980
)
# == Exercise Three ==
print("")
print("Function: add_together_and_double")
def add_together_and_double(num_a, num_b):
return (num_a + num_b) * 2
check_that_these_are_equal(
add_together_and_double(3, 4),
14
)
# When you're done, move on to 022_strings.py