forked from makersacademy/intro-to-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
021_two_step.py
77 lines (53 loc) · 1.73 KB
/
021_two_step.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
# Video alternative: https://vimeo.com/954334279/dd2abfbdd7#t=0
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):
# Divide num by two and add one to the result
pass # <-- This does nothing, replace it with your code
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):
# Multiply num by forty, and then add sixty
pass # <-- This does nothing, replace it with your code
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):
# Add together num_a and num_b, then double the result
pass # <-- This does nothing, replace it with your code
check_that_these_are_equal(
add_together_and_double(3, 4),
14
)
# When you're done, move on to 022_strings.py