Completed up to activity 20

This commit is contained in:
Uthman Fatih 2026-08-27 18:42:30 +01:00
parent 0985d4ff14
commit 1b43e8deb6
17 changed files with 104 additions and 8 deletions

View File

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 125 KiB

View File

@ -0,0 +1,30 @@
import turtle
my_screen = turtle.Screen()
terry = turtle.Turtle()
# Regular octagon in red
terry.pencolor("red")
terry.pendown()
count = 0
while count < 8:
terry.forward(50)
terry.right(45) # 360 / 8
count += 1
# Move turtle so shapes don't overlap
terry.penup()
terry.forward(200)
# Regular nonagon in blue
terry.pencolor("blue")
terry.pendown()
count = 0
while count < 9:
terry.forward(50)
terry.right(40) # 360 / 9
count += 1
my_screen.exitonclick()

View File

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

@ -1,8 +0,0 @@
# regular octagon in red
# regular nonagon in blue
# condition controlled iteration
# both shapes on same screen
import turtle

View File

Before

Width:  |  Height:  |  Size: 111 KiB

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

View File

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 57 KiB

BIN
17 Simple Menu/task.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 KiB

View File

@ -0,0 +1,18 @@
# Initialize as a clean empty list
foods = []
run = True
while run:
name = input("Enter a name: ")
food = input("Enter a favourite food: ")
foods.append([name, food])
user_choice = input("Would you like to add another student? (y/n): ")
if user_choice.strip().lower() == "n":
run = False
# Print in tabular format
print("\nName - Favourite Food")
print("-" * 25)
for person in foods:
print(f"{person[0]} - {person[1]}")

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

View File

@ -0,0 +1,56 @@
# loop:
# ask for name max length 10 (retry until suitable)
# ask for amount (hourly) (between 99p and £5.99) (retry until suitable)
# after user confirms they are done entering data,
# print out the data in tabular format with suitable column headings
# use main() function and functions with docstrings
def get_name():
collect = True
while collect:
name = input("Enter the activity: ")
if len(name) > 10:
print("Name too long. Please try again.")
continue
else:
collect = False
return name
def get_amount():
collect = True
while collect:
amount = float(input("Enter activity hourly rate in pence: "))
# if less than 99 pence or greater than 599
if amount < 99 or amount > 599:
print("Amount out of range. Please try again.")
continue
else:
collect = False
return amount
def print_data(data):
print("\nActivity - Amount")
print("-" * 15)
for activity in data:
print(f"{activity[0]} - {f"£{activity[1]/100}"}")
def main():
run = True
data = []
while run:
activity = get_name()
amount = get_amount()
print(f"{activity} - {f"£{amount/100}"}")
user_choice = input("Would you like to add another activity? (y/n): ")
if user_choice.strip().lower() == "n":
run = False
data.append([activity, amount])
print_data(data)
if __name__ == "__main__":
main()

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 KiB