Docsity

CodeHS Python | Unit 4 questions and answers Graded A+, Exams of Algorithms and Programming

Toggle sidebar
bg1
CodeHS Python | Unit 4 questions and
answers Graded A+
4.1.4: Do You Have a Cat? | CodeHS - โœ…โœ…"""
This program should declare a boolean that describes whether or
not you have a cat. Then you should print out an informative
message to the user.
"""
have_cat = False
print("Have a cat? " + str(have_cat))
4.2.6: Can You Graduate? | CodeHS - โœ…โœ…# Enter your code here
has_enough_units = False
has_met_requirements = False
can_graduate = has_enough_units or has_met_requirements
print("Can graduate? " + str(can_graduate))
4.2.7: School's Out | CodeHS - โœ…โœ…# Enter your code here
is_weekday = True
is_holiday = True
no_school_today = is_weekday or not is_holiday
print("There is no school today: " + str(no_school_today))
4.3.5: Rolling Dice | CodeHS - โœ…โœ…# Enter your code here
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download CodeHS Python | Unit 4 questions and answers Graded A+ and more Exams Algorithms and Programming in PDF only on Docsity!

CodeHS Python | Unit 4 questions and

answers Graded A+

4.1.4: Do You Have a Cat? | CodeHS - โœ…โœ…""" This program should declare a boolean that describes whether or not you have a cat. Then you should print out an informative message to the user. """ have_cat = False print("Have a cat? " + str(have_cat)) 4.2.6: Can You Graduate? | CodeHS - โœ…โœ…# Enter your code here has_enough_units = False has_met_requirements = False can_graduate = has_enough_units or has_met_requirements print("Can graduate? " + str(can_graduate)) 4.2.7: School's Out | CodeHS - โœ…โœ…# Enter your code here is_weekday = True is_holiday = True no_school_today = is_weekday or not is_holiday print("There is no school today: " + str(no_school_today)) 4.3.5: Rolling Dice | CodeHS - โœ…โœ…# Enter your code here

dice_first=int(input("first die? ")) print(str(dice_first)) dice_second=int(input("second die? ")) print(str(dice_second)) rolled_doubles= dice_first == dice_second print("Rolled doubles? " + str(rolled_doubles)) 4.3.6: All Star | CodeHS - โœ…โœ…# Enter your code here points=int(input("Points per game? ")) rebounds=int(input("Rebounds per game? ")) assist=int(input("Assist per game? ")) all_star= points>=25 or (points>=10 and rebounds>=10 and assist>=10) print("Is all star? " + str(all_star)) 4.4.7: Teenagers | CodeHS - โœ…โœ…# Enter your code here age = int(input("What is your age? ")) if age >= 13 and age<=19: print("Yes, you are a teenager.") else: print("No, you are a teenager.") 4.4.8: Meal Planner | CodeHS - โœ…โœ…# Enter your code here meal = input("What meal are you going to eat?") if meal == "breakfast":

add_key_down_handler(circle) 4.6.4: Meme Text Generator | CodeHS - โœ…โœ…# Enter your code here for i in range(50): print( "Takes one political science class. Knows how to solve the world's problems.") 4.6.5: The Worm | CodeHS - โœ…โœ…NUM_CIRCLES = 15

This graphics program should draw a worm.

A worm is made up of NUM_CIRCLES circles.

Use a for loop to draw the worm,

centered vertically in the screen.

Also, be sure that the worm is still drawn across

the whole canvas, even if the value of NUM_CIRCLES is changed.

radius = (get_width() / NUM_CIRCLES / 2) x = radius for i in range(NUM_CIRCLES): circ = Circle(radius) if i % 2 == 0: circ.set_color(Color.red) else: circ.set_color(Color.green) circ.set_position(x, get_height() / 2) add(circ)

current_spot = x x = current_spot + (radius * 2) 4.6.6: Caterpillar | CodeHS - โœ…โœ…NUM_CIRCLES = 15

This graphics program should draw a caterpillar.

A caterpillar is made up of NUM_CIRCLES circles.

The circles should alternate red - green - red - green, etc

Use a for loop to draw the worm,

centered vertically in the screen.

Also, be sure that the worm is still drawn across

the whole canvas, even if the value of NUM_CIRCLES is changed.

radius = (get_width() / NUM_CIRCLES / 2) x = radius for i in range(NUM_CIRCLES): circ = Circle(radius) if i % 2 == 0: circ.set_color(Color.red) else: circ.set_color(Color.green) circ.set_position(x, get_height() / 2) add(circ) current_spot = x x = current_spot + (radius * 2)

dice = ["1","2","3","4","5","6"] def allRolls(): for i in dice: for j in dice: print(i + "," + j) allRolls() 4.9.5: Lots of Dice | CodeHS - โœ…โœ…import random for i in range(100): roll = random.randint(1, 6) print(roll) 4.9.6: Random Color Square | CodeHS - โœ…โœ…import random rect = Rectangle(480,400) set_size(480, 400)

This graphics program should draw a square.

The fill color should be randomly choosen from

the COLORS list

SIDE_LENGTH = 100 COLORS = random.choice([Color.orange, Color.yellow, Color.green, Color.blue, Color.purple, Color.black, Color.gray]) rect.set_color(COLORS) add(rect)

4.10.4: Inventory | CodeHS - โœ…โœ…STARTING_ITEMS_IN_INVENTORY = 20 num_items = STARTING_ITEMS_IN_INVENTORY

Enter your code here

INVENTORY_ITEMS = 20 num = INVENTORY_ITEMS while num > 0: print("We have " + str(num) + " items in inventory.") To_Buy = int(input("How many would you like to buy? ")) if To_Buy > num: print("There is not enough in inventory for that purchase.") else: num = num - To_Buy if num > 0: print("Now we have " + str(num) + " left" ) print("All out!") Sorry about Fibonacci | CodeHS - โœ…โœ…I had never got the answer to it, again I apologize for the inconvenience. 4.11.4 Snake Eyes | CodeHS - โœ…โœ…import random

Enter your code here

num_rolls = 0 while True: