100일간의 코드: 2022년을 위한 완벽한 Python Pro 부트캠프 - 5일차(FizzBuzz)

16872 단어
연습 5.1 - 평균 높이

#🚨 Don't change the code below 👇
student_heights = input("Input a list of student heights ").split()
for n in range(0, len(student_heights)):
  student_heights[n] = int(student_heights[n])
#🚨 Don't change the code above 👆


#Write 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"Total students = {number_of_students}")

average_height = round(total_height / number_of_students)


연습 5.2 - 높은 점수

#The aim of the exercise is to use a For Loop function not a max() or min()

#🚨 Don't change the code below 👇
student_scores = input("Input a list of student scores ").split()
for n in range(0, len(student_scores)):
  student_scores[n] = int(student_scores[n])
print(student_scores)
🚨 Don't change the code above 👆

#Write your code below this row 👇

top_score = 0
for score in student_scores:
  if score > top_score:
    top_score = score
    #print(top_score)

print(f"The highest score in the class is: {top_score}")
print(average_height)


연습 5.3 - 1 - 100 사이의 짝수 더하기

#Write your code below this row 👇

total = 0
for number in range(1, 101):
    if(number %2 == 0):
        total += number
print(total)


연습 5.4 - FizzBuzz lol

#Write your code below this row 👇

for fizzbuzz in range(1, 101):
    if fizzbuzz % 3 == 0 and fizzbuzz % 5 == 0:
        print("Fizzbuzz")
        continue
    elif fizzbuzz % 3 == 0:
        print("Fizz")
        continue
    elif fizzbuzz % 5 == 0:
        print("Buzz")
        continue
    print(fizzbuzz)


프로젝트 - 비밀번호 생성기

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 = ['!', '#', '$', '%', '&', '(', ')', '*', '+']

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"))

#Easy Level - Order not randomized:
#e.g. 4 letter, 2 symbol, 2 number = JduE&!91**

password = ""

for char in range(1, nr_letters + 1):
  password += random.choice(letters)

for char in range(1, nr_symbols + 1):
  password += random.choice(symbols)

for char in range(1, nr_numbers + 1):
  password += random.choice(numbers)

print(password)

#Hard Level - Order of characters randomized:
#e.g. 4 letter, 2 symbol, 2 number = g^2jk8&P**

password_list = []

for char in range(1, nr_letters + 1):
  password_list.append(random.choice(letters))

for char in range(1, nr_symbols + 1):
  password_list += random.choice(symbols)

for char in range(1, nr_numbers + 1):
  password_list += random.choice(numbers)

random.shuffle(password_list)

password = ""

for char in password_list:
  password += char

print(f"Your new password is: {password} ")

좋은 웹페이지 즐겨찾기