Skip to content

Commit eb213d8

Browse files
authored
Merge Challenges from joes-branch (#2)
@boinary Thanks for the review, merging this code.
2 parents 01e4a72 + b770a71 commit eb213d8

14 files changed

+342
-24
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
startingRadius = (25 * 4)
2+
radiusGrowth = 25
3+
4+
def draw_concentric_circles(m_radius, m_growth):
5+
penup()
6+
right(90)
7+
forward(startingRadius)
8+
left(90)
9+
for i in range(4):
10+
pendown()
11+
begin_fill()
12+
color_choice = input("Choose a color for circle " + str(i) + ": ")
13+
color(color_choice)
14+
circle(startingRadius - (radiusGrowth * i))
15+
end_fill()
16+
penup()
17+
left(90)
18+
forward(radiusGrowth)
19+
right(90)
20+
21+
draw_concentric_circles(startingRadius, radiusGrowth)

CodeHS/2/12/5/Four Corners-Joe.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def drawCube(side_len):
2+
pendown()
3+
for i in range(16): # 16 beacuse codehs is dumb
4+
forward(side_len)
5+
left(90)
6+
penup()
7+
8+
penup()
9+
setposition(-200, -200)
10+
for i in range(4):
11+
square_length = input("Enter square size: ")
12+
drawCube(square_length)
13+
forward(400)
14+
left(90)
15+
print("Done!")
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
numCircles = 8
2+
circleSize = 20
3+
4+
speed(0)
5+
def make_caterpillar_cell(color_choice, m_size):
6+
pendown()
7+
begin_fill()
8+
color(color_choice)
9+
circle(m_size)
10+
end_fill()
11+
penup()
12+
advance_to_next(m_size)
13+
14+
def advance_to_next(m_size):
15+
penup()
16+
forward(m_size * 2)
17+
18+
penup()
19+
setposition(-100, 0)
20+
for i in range(numCircles):
21+
make_caterpillar_cell(input("Color for cell " + str(i + 1) + ": "), circleSize)
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
circleColor = "Blue" # Set color of the circle
2+
squareColor = "Red" # Set color of the square
3+
4+
def circle_in_square(radius): # Pass radius to the def
5+
pendown()
6+
begin_fill()
7+
color(squareColor)
8+
forward(radius)
9+
for i in range(3):
10+
left(90)
11+
forward(int(radius) * 2)
12+
print("Drawing square with radius " + str(int(radius * 2)))
13+
left(90)
14+
forward(radius)
15+
end_fill() # Finish Square
16+
begin_fill() # Start Circle
17+
print("Drawing Circle with radius " + str(radius))
18+
color(circleColor)
19+
circle(radius)
20+
end_fill()
21+
22+
circle_in_square(input("Shape Size: ")) # Ask for user input

CodeHS/2/13/6/Snowman-Joe.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
This program made by Joe
3+
"""
4+
snowman_list = []
5+
6+
def draw_snowman(m_inputs):
7+
for current_ball in m_inputs:
8+
pendown()
9+
color("grey")
10+
begin_fill()
11+
circle(int(current_ball))
12+
end_fill()
13+
penup()
14+
left(90)
15+
forward(2 * int(current_ball))
16+
right(90)
17+
18+
def draw_sequential_snowman(m_input):
19+
for i in range(3):
20+
pendown()
21+
color("grey")
22+
begin_fill()
23+
circle(m_input)
24+
m_input = m_input / 2
25+
end_fill()
26+
penup()
27+
left(90)
28+
forward(4 * int(m_input))
29+
right(90)
30+
31+
penup()
32+
setposition(0,-200)
33+
for i in range(3):
34+
user_input = input("Size for ball " + str(i + 1) + ": ")
35+
snowman_list.append(user_input)
36+
#draw_snowman(snowman_list)
37+
draw_sequential_snowman(100)
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
This program made by Joe
3+
"""
4+
startingRadius = 25
5+
radiusGrowth = 25
6+
7+
def draw_concentric_circles(m_radius, m_growth):
8+
for i in range(4):
9+
circle(m_radius + (m_growth * i))
10+
right(90)
11+
penup()
12+
forward(m_growth)
13+
pendown()
14+
left(90)
15+
16+
draw_concentric_circles(startingRadius, radiusGrowth)

CodeHS/2/16/4/Happy Face-Joe.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""
2+
This program made by Joe
3+
"""
4+
def startDraw(requestedColor):
5+
pendown()
6+
color(requestedColor)
7+
begin_fill()
8+
9+
def stopDraw():
10+
end_fill()
11+
penup()
12+
13+
def drawSmile(happy, headcolor, headsize):
14+
eyeHeight = headsize * 1.5
15+
16+
startDraw(headcolor)
17+
circle(headsize)
18+
stopDraw()
19+
forward(headsize * 0.6)
20+
left(90)
21+
forward(eyeHeight)
22+
left(90)
23+
for i in range(2):
24+
forward(headsize * 0.3)
25+
startDraw("Black")
26+
circle(headsize * 0.1)
27+
stopDraw()
28+
forward(headsize * 0.3)
29+
left(90)
30+
forward(eyeHeight)
31+
left(90)
32+
forward(headsize * 0.6)
33+
34+
if (happy == "happy"):
35+
left(90)
36+
forward(headsize * 0.8)
37+
left(90)
38+
forward(headsize * 0.5)
39+
left(90)
40+
startDraw("Black")
41+
circle(headsize * 0.5, 180)
42+
left(90)
43+
forward((headsize * 0.5) * 2)
44+
stopDraw()
45+
elif (happy == "sad"):
46+
left(90)
47+
forward(headsize * 0.4)
48+
right(90)
49+
forward(headsize * 0.5)
50+
left(90)
51+
startDraw("Black")
52+
circle(headsize * 0.5, 180)
53+
left(90)
54+
forward((headsize * 0.5) * 2)
55+
stopDraw()
56+
else:
57+
print("Error in input, expected 'happy' or 'sad'")
58+
print(happy)
59+
60+
drawSmile(input("Input your mood, supported inputs are: happy, sad:"), "Yellow", 80)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
This program made by Joe
3+
"""
4+
numSquares = 6
5+
squareSize = 20
6+
7+
def doSquares():
8+
for square in range(numSquares):
9+
if (square % 2 == 0):
10+
begin_fill()
11+
for i in range(4):
12+
forward(squareSize)
13+
left(90)
14+
end_fill()
15+
penup()
16+
forward(20 + squareSize)
17+
pendown()
18+
19+
doSquares()

CodeHS/2/19/6/Checkerboard-Joe.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
This program made by Joe
3+
"""
4+
square_width = 40
5+
6+
speed(0)
7+
def drawModCube(cube_id):
8+
pendown()
9+
if (cube_id % 2 == 0):
10+
color("Red")
11+
else:
12+
color("Black")
13+
begin_fill()
14+
for i in range(4):
15+
forward(square_width)
16+
left(90)
17+
end_fill()
18+
penup()
19+
forward(square_width)
20+
21+
penup()
22+
setposition(-200,-200)
23+
for colum in range((400 / square_width)):
24+
for row in range((400 / square_width)):
25+
drawModCube(row + colum)
26+
setposition(-200,-200)
27+
left(90)
28+
forward(square_width * (colum + 1))
29+
right(90)

CodeHS/2/9/7/Kid's Shapes Toy-Joe.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
This program made by Joe
3+
"""
4+
shapeSize = 60
5+
6+
def draw_polygon(m_sides, m_color, m_size): # Passed variables are translated to these member variables as they enter the def
7+
pendown()
8+
begin_fill()
9+
color(m_color)
10+
circle(m_size, 360, m_sides) # Function draws a circle of m_size, 360 degrees, with m_sides, making full polygons.
11+
end_fill()
12+
penup()
13+
14+
def draw_circle(m_angle, m_color, m_size):
15+
pendown()
16+
begin_fill()
17+
color(m_color)
18+
if (m_angle != 360):
19+
circle(m_size, m_angle)
20+
else:
21+
circle(m_size)
22+
end_fill()
23+
penup()
24+
25+
penup()
26+
setposition(100, (-100 - shapeSize))
27+
draw_polygon(5, "green", shapeSize) # We pass 5 for the value of sides, green as the color, and shapeSize as the size of our circle
28+
setposition(-100, (100 - shapeSize))
29+
draw_polygon(4, "red", shapeSize)
30+
setposition(100, (100 - shapeSize))
31+
draw_circle(360, "blue", shapeSize)
32+
setposition(-100, (-100 - shapeSize))
33+
draw_circle(180, "yellow", shapeSize)
34+
color("black")
35+
setposition(0, 0)

CodeHS/3/5/9/Recipe-Joe.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
This program made by Joe S
3+
"""
4+
5+
servings = -1 # Set the servings to a null value
6+
shopping_list = ["mixed greens", "blueberries", "walnuts"] # Create a list of all the things we need to shop for
7+
8+
object_list = [] # Create an empty list where we will store objects
9+
10+
class ingredient(): # This class defines the ingredient object
11+
def __init__(self, name, qty): # This init function takes the name and qty, and asigns it to the object in question
12+
self.name = name
13+
self.qty = qty
14+
def list_total(self): # This function lists the content of the current item in a human readable way
15+
print("Total ounces of " + self.name + ": " + str(float(self.qty) * servings))
16+
17+
for listitem in shopping_list: # For every item on our shopping list
18+
print("Enter ingredient 1: " + str(listitem))
19+
object_list.append(ingredient(listitem, input("Ounces of " + str(listitem) + ": "))) # Create a new object, add it to our list using inputs from the user
20+
21+
servings = float(input("Enter total number of servings: ")) # Ask the user for the total number of servings
22+
print("") # Print a blank line
23+
for item in object_list: # For every object in our object list
24+
item.list_total() # call that objects respective list_total function

CodeHS/3/5/9/recipe.py

-24
This file was deleted.

CodeHS/4/3/10/Transaction-Joe.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
This program made by Joe
3+
"""
4+
total_balance = 1000
5+
min_bank = 0
6+
loop_overun_protection = 0
7+
8+
while loop_overun_protection < 20:
9+
user_input = input("deposit or withdrawal? ")
10+
if user_input == "deposit":
11+
print("Your current balance is $" + str(total_balance))
12+
total_balance = total_balance + int(input("How much to deposit? "))
13+
print("Your current balance is now $" + str(total_balance))
14+
elif user_input == "withdrawal":
15+
print("Your current balance is $" + str(total_balance))
16+
temp_balance = int(input("How much to withdrawal? "))
17+
if total_balance - temp_balance <= min_bank:
18+
print("You cannot have a negative balance!")
19+
else:
20+
total_balance = total_balance - temp_balance
21+
print("Your current balance is now $" + str(total_balance))
22+
else:
23+
print("Invalid transaction")
24+
loop_overun_protection = loop_overun_protection + 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
This program made by Joe
3+
"""
4+
userage = bool(int(input("Age: ")) >= 35)
5+
user_birthplace = bool(input("Born in the US? (Yes/No): ") == "Yes")
6+
user_residency = bool(int(input("Years of Residency: ")) >= 14)
7+
8+
if (userage and user_birthplace) and user_residency:
9+
print("You are eligible to run for president.")
10+
else:
11+
print("You are not eligible to run for president.")
12+
13+
if userage != True:
14+
print("You are too young. You must be at least 35 years old.")
15+
if user_birthplace != True:
16+
print("You must be born in the U.S. to run for president.")
17+
print(user_residency)
18+
if user_residency != True:
19+
print("You have not been a resident for long enough.")

0 commit comments

Comments
 (0)