Saturday, May 2, 2026

Week 1 Notes


# Python Problem Solver
# Week 1 Example 1: the Alphabet
#
for i in range(26):
    print(chr(48 + i), end = "")
print()

# Python Problem Solver
# Week 1 Example 2: Mission Artemis
#

# Initialise mission data

crew2 = 4
crew3 = 4
days2 = 10
days3 = 30
oxpd = 5
fdpd = 3
maxox = 800
maxfd = 500

# Get user choice of mission
# Keep asking if input not valid

mission = int(input("Enter a mission number: "))
while mission != 2 and mission != 3:
    mission = int(input("Enter a mission number: "))

# Calculate total oxygen and food consumption

if mission == 2:
    missionname = "Artemis II"
    crew = crew2
    days = days2
elif mission == 3:
    missionname = "Artemis III"
    crew = crew3
    days = days3

totalox = crew * days * oxpd
totalfd = crew * days * fdpd

# Decide whether it's safe to launch

if totalox <= maxox and totalfd <= maxfd:
    safe = True
    print("+--------------------------+")
    print("|     READY FOR LAUNCH!    |")
    print("+--------------------------+")
else:
    safe = False
    print("+--------------------------+")
    print("|   NOT SAFE TO LAUNCH!    |")
    print("+--------------------------+")

# Print mission report

print(f"Mission: {missionname}")
print("Spaceship: Orion")
print(f"Crew: {crew}")
print(f"Days: {days}")
print(f"Oxygen needed: {totalox} units")
print(f"Food needed: {totalfd} units")
if safe:
    print("Status: READY FOR LAUNCH")
else:
    print("Status: NOT SAFE TO LAUNCH")

# Python Problem Solver
# Week 1 Example 3: Drawing flags using Python Turtle
#

# Import all classes and functions from Turtle
from turtle import *

# Initialise turtle

shape("arrow")
speed(10)

# Set screen background

Screen().bgcolor("#DDDDDD")

# Draw the frame for the flag

color("white")
pensize(2)
fillcolor("white")

# Position the pen in the bottom left corner

penup()
goto(-180, -120)
pendown()
begin_fill()
goto(180,-120)
goto(180,120)
goto(-180,120)
goto(-180, -120)
end_fill()  
  
#Draw the blue stripe

color("blue")
pensize(2)
fillcolor("blue")

penup()
goto(-180, -120)
pendown()
begin_fill()
goto(-60,-120)
goto(-60,120)
goto(-180,120)
goto(-180, -120)
end_fill()  

#Draw the red stripe

color("red")
pensize(2)
fillcolor("red")

penup()
goto(60, -120)
pendown()
begin_fill()
goto(180,-120)
goto(180,120)
goto(60,120)
goto(60, -120)
end_fill()  


# Adding Text...
penup()
goto(-62, -160)
color("white")
write("FRANCE", None, "left", ("Arial", 24, "bold"))

# Finish up

hideturtle()
input()

No comments:

Post a Comment

Week 8 Assignments