forked from AguaClara/aguaclara_tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInteractive-Tutorial-2-Python-Basics.py
120 lines (90 loc) · 3.54 KB
/
Interactive-Tutorial-2-Python-Basics.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
#######################################################################
# Interactive Tutorial 2: Python Basics
#######################################################################
# Comments beginning with "TODO" contain the tasks that you must
# complete in this interactive tutorial. Write your answers under each
# TODO. Use Find (Ctrl/Cmd + F) to keep track of them.
#
# This is a Python file, not the interactive interpreter, so code won't
# run immediately when you write it. You also WON'T need the triple
# greater-than symbols (>>>) at the beginning of each line.
#
# Just focus on writing Python to the best of your abilities! Once
# you're done, you'll have the chance to check your work in the next
# tutorial section, Running Python Code: https://bit.ly/2w3PbCX
#######################################################################
#######################################################################
# Don't touch this! This is for testing your code.
#######################################################################
from tests.prints import start_recording, stop_recording, get_prints
from tests.tutorial2 import test_todos
start_recording()
#######################################################################
# TODO 1: Write Monroe's favorite food in a string.
#
# Hint: It's rice and beans. Yum, string beans.
f = 'rice and beans'
print(f)
# TODO 2: Calculate the volume of a 7 x 7 x 5 cube using Python math
# operations.
vol = 7 ** 2 * 5
print(vol)
# TODO 3: Pop the last item from this list, append 'filtration' to it,
# then change the second item to '1 LPS'. Don't change the original
# list.
#
# Hint: what number do Python lists start from? Check the lists section
# in the Writing Python Code tutorial if you're unsure.
hydraulic_processes = ['flocculation', 'sedimentation', 'stirring']
hydraulic_processes.pop()
hydraulic_processes.append('filtration')
hydraulic_processes[1] = '1 LPS'
print(hydraulic_processes)
# TODO 4: Change the value of the second entry in this dict to 'bacon'.
# Don't change the original dict.
analogy = {'knowledge' : 'power', 'France': 'ham'}
analogy['France'] = 'bacon'
print(analogy['knowledge'] + ' ' + analogy['France'])
# TODO 5: Write a conditional statement that determines if both of
# the following conditions are met:
# - Either a or b are True
# - c is False
# If both conditions are met, set does_it_work to 'yes'. Otherwise,
# set it to 'no'.
# Don't try to figure these variables out! Just write a conditional
# that determines if the above conditions are met.
a = True
b = True
c = False
passes = 'not yet determined'
if((a or b) and not c):
passes = 'yes'
else:
passes = 'no'
print(passes)
# TODO 6: Write a for loop that multiplies x by each integer from 1 to
# 30.
#
# Hint: what does += do? Check the for loops section in the Writing
# Python Code tutorial if you're unsure. Try it with multiplication.
x = 1
for i in range(1, 30):
x *= i
print(x)
# TODO 7: Write a function called 'squared' that takes in a number and
# returns its square (to the power of 2). Then, call that function so
# that x is squared 6 times.
#
# Hint: Don't copy and paste the function 6 times!
x = 4
def squared(number):
return number **2
for i in range(6):
x = squared(x)
print(x)
#######################################################################
# Don't touch this! This is for testing your code.
#######################################################################
stop_recording()
test_todos(get_prints())
#######################################################################