Completed up to activity 20
|
Before Width: | Height: | Size: 125 KiB After Width: | Height: | Size: 125 KiB |
30
12 Create a Shape/exercise-01.py
Normal 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()
|
||||||
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
@ -1,8 +0,0 @@
|
|||||||
# regular octagon in red
|
|
||||||
# regular nonagon in blue
|
|
||||||
|
|
||||||
# condition controlled iteration
|
|
||||||
# both shapes on same screen
|
|
||||||
|
|
||||||
import turtle
|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 111 KiB |
BIN
14 Practice in the Shell/task.png
Normal file
|
After Width: | Height: | Size: 112 KiB |
BIN
14/image.png
|
Before Width: | Height: | Size: 36 KiB |
BIN
15 Practice in the Python Shell/task.png
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
15/image.png
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 57 KiB |
BIN
17 Simple Menu/task.png
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
18 Putting it all Together/task.png
Normal file
|
After Width: | Height: | Size: 212 KiB |
18
19 Develop the Favourite Foods Program/exercise-01.py
Normal 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]}")
|
||||||
BIN
19 Develop the Favourite Foods Program/task.png
Normal file
|
After Width: | Height: | Size: 82 KiB |
56
20 Fundraiser part 1/excerise-01.py
Normal 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()
|
||||||
|
|
||||||
BIN
20 Fundraiser part 1/task.png
Normal file
|
After Width: | Height: | Size: 245 KiB |