Accounting /Unit 4 Code HS Python

Unit 4 Code HS Python

Accounting21 CardsCreated 3 months ago

This flashcard set features beginner-friendly programming exercises from CodeHS that focus on Boolean variables, logical operators, and conditional statements in Python. It helps students practice making decisions in code using user input, comparisons, and logical reasoning to solve simple real-world problems.

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))

Tap or swipe ↕ to flip
Swipe ←→Navigate
SSpeak
FFocus
1/21

Key Terms

Term
Definition

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 t...

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
pr...

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 tod...

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(dic...

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...

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:

Related Flashcard Decks

Study Tips

  • Press F to enter focus mode for distraction-free studying
  • Review cards regularly to improve retention
  • Try to recall the answer before flipping the card
  • Share this deck with friends to study together
TermDefinition

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":
print("How about some avocado")
else:
if meal
"lunch":
print("How about some pizza?")
else:
if meal == "dinner":
print("How about some chicken")

4.5.4: Growing Circle | CodeHS

# Start coding here. Don't forget to click the canvas
# before you try to use the arrow keys!
circ = Circle(100)
circ.set_position(250, 250)
circ.set_color(Color.blue)
add(circ)
def circle(event):
if event.key "ArrowLeft":
circ.set_radius(circ.get_radius() - 10)
if event.key
"ArrowRight":
circ.set_radius(circ.get_radius() + 10)
if event.key "ArrowUp":
circ.set_radius(circ.get_radius() + 10)
if event.key
"ArrowDown":
circ.set_radius(circ.get_radius() - 10)


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)

4.7.5: Count By Sevens | CodeHS

# Enter your code here
for i in range(0, 500, 7):
print(i)

4.7.6: Powers of Two | CodeHS

# Enter your code here
for i in range(20):
print(2**i)

4.8.4: Better Sum | CodeHS

# Enter your code here
firstnum = int(input("What is your frist number?: "))
lastnum = int(input("What is your second number?: "))
sum = 0
for i in range(firstnum, lastnum + 1):
sum += i
print(sum)

4.8.5: Factorial | CodeHS

# Enter your code here
number=int(input("What is your number?"))
sum=1
for i in range(1, number+1):
sum*=i
print(str(sum))

4.8.6: All Dice Values | CodeHS

# Put your code here
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!")

4.11.4 Snake Eyes | CodeHS

import random
# Enter your code here
num_rolls = 0
while True:
num_rolls += 1
dice_one = random.randint(1, 6)
dice_two = random.randint(1, 6)
print("Rolled: " + str(dice_one) + " " + str(dice_two))

if (dice_one 1 and dice_two 1):
print("It took you " + str(num_rolls) + " rolls to get snake eyes.")
break

4.11.5: Better Password Prompt | CodeHS

SECRET = "abc123"
# Enter your code here
while True:
password = input("Enter password: ")
if password == SECRET:
print("You got it!")
break
else:
print("Sorry, that did not match. Please try again.")