Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save under-script/f711f89a2552cd42d285aeeeb9985afd to your computer and use it in GitHub Desktop.
Save under-script/f711f89a2552cd42d285aeeeb9985afd to your computer and use it in GitHub Desktop.
Day 5 - Beginner - Python Loops
#For Loop with Lists
fruits = ["Apple", "Peach", "Pear"]
for fruit in fruits:
print(fruit)
print(fruit + " Pie")
print(fruits)
# Input a Python list of student heights
student_heights = input().split()
for n in range(0, len(student_heights)):
student_heights[n] = int(student_heights[n])
# Your code below this row ๐Ÿ‘‡
total_height = 0
for height in student_heights:
total_height += height
print(f"total height = {total_height}")
number_of_students = 0
for student in student_heights:
number_of_students += 1
print(f"number of students = {number_of_students}")
average_height = round(total_height / number_of_students)
print(f"average height = {average_height}")
# Input a list of student scores
student_scores = input().split()
for n in range(0, len(student_scores)):
student_scores[n] = int(student_scores[n])
# Your code below this row ๐Ÿ‘‡
highest_score = student_scores[0]
for score in student_scores[1:]:
if score > highest_score:
highest_score = score
print(f"The highest score in the class is: {highest_score}")
# #For Loops with Lists
# fruits = ['Apple', 'Peach', 'Pear']
# for fruit in fruits:
# print(fruit)
# print(fruit, 'Pie')
#
# #For Loop with Range
# for number in range(1, 11, 3):
# print(number)
total = 0
for number in range(1, 101):
total += number
print(total)
target = int(input()) # Enter a number between 0 and 1000
# ๐Ÿšจ Do not change the code above โ˜๏ธ
# Write your code here ๐Ÿ‘‡
total = 0
for number in range(1, target + 1):
if number % 2 == 0:
total += number
print(total)
# Write your code here ๐Ÿ‘‡
for number in range(1, 101):
if number % 3 == 0 and number % 5 == 0:
print('FizzBuzz')
elif number % 3 == 0:
print('Fizz')
elif number % 5 == 0:
print('Buzz')
else:
print(number)
#Password Generator Project
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 = ['!', '#', '$', '%', '&', '(', ')', '*', '+']
nested = [letters, numbers, symbols]
print("Welcome to the PyPassword Generator!")
# nr_letters= int(input("How many letters would you like in your password?\n"))
# nr_symbols = int(input(f"How many symbols would you like?\n"))
# nr_numbers = int(input(f"How many numbers would you like?\n"))
password = ''
for i in range(1, 9):
password += random.choice(random.choice(nested))
print(f"Here's your password: {password}")
#Eazy Level - Order not randomised:
#e.g. 4 letter, 2 symbol, 2 number = JduE&!91
#Hard Level - Order of characters randomised:
#e.g. 4 letter, 2 symbol, 2 number = g^2jk8&P
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment