-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDAY_5.py
More file actions
104 lines (61 loc) · 1.66 KB
/
Copy pathDAY_5.py
File metadata and controls
104 lines (61 loc) · 1.66 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
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
#!/usr/bin/env python
# coding: utf-8
# # Python Loops
# In[6]:
fruits = ['apple', 'peach', 'pear']
for fruit in fruits :
print(fruit)
print(fruit + " Pie")
# print(fruits) # gets printed everytime for loop is executed
print(fruits) # gets printed just after the loop terminates
# In[37]:
# Range Function - iterates over the given numbers or lists
sum_ = 0
for number in range(1, 101): # second number isn't included
sum_ += number
print(sum_)
# # AVERAGE HEIGHT
# In[21]:
# Complete the challenge without using len() and sum()
student_heights = input("Input a list of student heights. \n").split()
total_height = 0
items = 0
for n in range(0, len(student_heights)):
student_heights[n] = int(student_heights[n])
total_height += student_heights[n]
items += 1
average = total_height / items
print(average)
# # HIGHEST SCORE
# In[30]:
student_scores = [78, 65, 89, 86, 55, 91, 64, 89]
highest_score = student_scores[0]
for score in student_scores:
if score > highest_score:
highest_score = score
print(f"The highest score in the class is: {highest_score}")
# # ADDING EVENS
# In[45]:
# Calculate sum of all even numbers from 1-100 inclusive.
even_sum = 0
for num in range(2, 101, 2):
even_sum += num
print(even_sum)
# OR
total = 0
for num in range(2, 101):
if num %2 == 0:
total += num
print(total)
# # FIZZ BUZZ
# In[49]:
print("Welcome to the FizzBuzz Game!")
for num in range(1, 101):
if (num %3 == 0) and (num %5 == 0):
print("FizzBuzz")
elif num %3 == 0:
print("Fizz")
elif num %5 == 0:
print("Buzz")
else:
print(num)