Saturday, June 13, 2026

Week 7 Notes


# Python Problem Solver
# Week 7 Example 1: YOLO
#

line = input()
# Split input into a list of words in list2
list1 = line.split()
# list2 is used for output
list2 = []

for word in list1:
    # For each word in list1, append its 1st character to the end of list2
    list2.append(word[0])

# Join all the "1st characters" into 1 string and conver to upper case
print("".join(list2).upper())


# Python Problem Solver
# Week 7 Example 2: Optical Illusions
#

from turtle import *

speed(10)

def drawCircle(x, y, r, c):
    penup()
    pencolor(c)
    fillcolor(c)
    goto(x, y - r)
    pendown()
    begin_fill()
    circle(r)
    end_fill()
    penup()
    hideturtle()

# Pay attention to all the coordinates are calcuated
drawCircle(-50, 0, 30, "purple")
drawCircle(-150, 0, 50, "black")
drawCircle(-50, 100, 50, "black")
drawCircle(50, 0, 50, "black")
drawCircle(-50, -100, 50, "black")

drawCircle(250, 0, 30, "purple")
drawCircle(310, 0, 10, "black")
drawCircle(250, -60, 10, "black")
drawCircle(190, 0, 10, "black")
drawCircle(250, 60, 10, "black")

input()


# Python Problem Solver
# Week 7 Example 3: Calculating Pi
#

N = int(input())

sum = 0
for n in range(1, N+1):
    sum += 1/(n*n)
answer = (sum * 6) ** .5
print(f"The {N}-th approximation of Pi is {answer}")

No comments:

Post a Comment

Week 8 Assignments