Skip to content

Instantly share code, notes, and snippets.

@seunoyeniyi
Created May 18, 2023 20:23
Show Gist options
  • Save seunoyeniyi/84e58af71923f6285a539edb7bf75c60 to your computer and use it in GitHub Desktop.
Save seunoyeniyi/84e58af71923f6285a539edb7bf75c60 to your computer and use it in GitHub Desktop.
Final Lab Assignment
#OYENIYI SEUN TAIWO
#CSC/2021/235
def car_price(price, years):
if years == 0:
return round(price, 2)
else:
percentagePrice = price * 0.8
print("Price:", round(percentagePrice,2))
return car_price(percentagePrice, years - 1)
final_price = car_price(10000, 10)
print("Final Price:", final_price)
#OYENIYI SEUN TAIWO
#CSC/2021/235
import turtle
import math
t = turtle.Turtle()
# this function draw a single perpendicular (vertical and horizontal 90 degree) line
def draw(x, y, length):
# draw horizontal
t.penup()
t.goto(x, y)
t.pendown()
t.setheading(0) # Set the turtle's heading to hozizontal
t.forward(length)
# draw vertical
t.penup()
t.goto(x + (length/2), y)
t.pendown()
t.setheading(90) # Set the turtle's heading to face upwards
t.forward(length)
# recursive function
def recursive_draw(x, y, length):
if length <= 1:
return
draw(x, y, length)
new_length = length / math.sqrt(2)
recursive_draw(x + new_length/2, y + new_length/2, new_length)
start_x = -200
start_y = -200
line_length = 300
recursive_draw(start_x, start_y, line_length)
turtle.done()
#OYENIYI SEUN TAIWO
#CSC/2021/235
from turtle import *
def fractal(order, size):
if order == 1:
forward(size)
else:
forward(size)
left(60)
fractal(order-1, size/3)
backward(size/3)
right(60)
fractal(order-1, size/3)
backward(size/3)
right(60)
fractal(order-1, size/3)
backward(size/3)
left(60)
left(90)
fractal(3, 250)
exitonclick()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment