-
Notifications
You must be signed in to change notification settings - Fork 0
/
intro to python activity solution
83 lines (68 loc) · 1.7 KB
/
intro to python activity solution
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
# current_temp_in_f = c_to_f(current_temp_in_c)
#current_temp_in_c = f_to_c(current_temp_in_f)
#print("The current temp in fahrenheit is: ", current_temp_in_c ," degrees.")
#variables
# todo 1
str1 = "Hello"
str2 = "World!"
print(str1 + str2)
#print(str1 - str2) does not work
#print(str1 / str2) does not work
#print(str1 * str2) does not work
# todo 2
float1 = 3.14159165
float2 = 6.62607015
print(float1 + float2)
print(float1 - float2)
print(float1 / float2)
print(float1 * float2)
# todo 3
bool1 = True
bool2 = False
print(bool1 + bool2) # True + False = 1
print(bool1 - bool2) # True - False = 1
print(bool1 * bool2) # True * False = 0
#print(bool1 / bool2) gives error
print(bool1 + bool1) # True + True = 2
print(bool1 - bool1) # True - True = 0
print(bool1 * bool1) # True * True = 1
print(bool1 / bool1) # True / True = 1.0
#Lists, Dictionaries, and Tuples
colors_list = ["red", "yellow", "blue", "green", "purple"]
colors_list.insert(5,"black")
print(colors_list)
colors_list.append("white")
print(colors_list)
colors_list[0] = "pink"
print(colors_list)
#For loops, while loops, and if statements
#block 1
x = 1
while(x < 10):
if(x == 3):
print("fizz")
x +=1
elif(x == 5):
print("buzz")
x +=1
else:
print(x)
x +=1
#block 2
fruits_and_veggies = [["Apple", "Banana", "Orange"], ["Broccoli", "Peas", "Carrots"]]
for i in fruits_and_veggies:
for j in i:
print(j)
#block 3
a = [1, 2, 3, 4, 5]
b = [6, 7, 8, 9, 10]
for i in a:
b.insert(0,i)
print(b)
#functions
current_temp_in_f = 64.4
def f_to_c(temp_f):
temp_c = (temp_f - 32) * 5/9
return temp_c
current_tempt_in_c = str(f_to_c(current_temp_in_f))
print("The current temp in celsius is: " + current_tempt_in_c + " degrees.")