Using the for loop with Python List
fruits = ["Apple", "Peach", "Strawberry"]
for fruit in fruits:
print(fruit)
Average Height Exercise
studentHeights = input("Put in the heights for the students: ").split(",")
newArr = []
total = 0
for i in range(0, len(studentHeights)):
newArr.append(int(studentHeights[i]))
for i in range(0, len(newArr)):
total += newArr[i]
averageHeight = int(total/len(newArr))
print(averageHeight)
Highest Score Exercise
score = input("Type in the scores: ").split(",")
scoreArr = []
for i in range(0, len(score)):
scoreArr.append(int(score[i]))
high = max(scoreArr)
print(f"The highest score in the class: {high}" )
Range Function
for number in range(1,10):
print(number)
Adding Evens Exercises
total = 0
for numbers in range(1,101):
if numbers % 2 == 0:
total += numbers
print(total)
Fizz Buzz Exercises
for i in range(1,101):
if i % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)
Password Generator
import random
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']
le = int(input("How many letters in the pw: "))
n = int(input("How many numbers in the pw: "))
s = int(input("How many symbols in the pw: "))
pw = ""
for i in range(1, le+1):
pw += random.choice(letters)
for i in range(1, n + 1):
pw += random.choice(numbers)
for i in range(1, s + 1):
pw += random.choice(symbols)
l = list(pw)
random.shuffle(l)
result = ''.join(l)
print(result)