# Use while loops to solve the following challenges
# A. Count down from 100 to 0 with a loop, including a print statement
for num in range(100,0,-1):
#print(num)
num-=1
print(num)
num = 100
while num >0:
#print(num)
num -=1
print(num)
# B. Construct a string consisting of 20 "a" characters in a row
value = ""
while len(value) < 20:
value+="a"
print(value)
# C. Bring down the price variable by increments of 10 until it is lower than the acceptable_price
price = 1000
acceptable_price = 954
price = 1000
acceptable_price = 954
while price > acceptable_price:
price-=10
print(price)
# D. Spring cleaning: remove all instances of "mess" from the garage_contents list
# Hint: Use the in operator to check if "mess" is still in the list, and .remove() to get rid of it
garage = ["bike", "mess", "generator", "mess", "mess", "tools", "car", "mess"]
garage = ["bike", "mess", "generator", "mess", "mess", "tools", "car", "mess"]
while "mess" in garage:
garage.remove("mess")
print(garage)
# Use for loops to solve the following challenges
# A. Print through each number in the numbers list
numbers = [2,3,5,8]
numbers = [2,3,5,8]
for num in numbers:
print(num)
# B. Add each of the numbers to the sum_total variable.
sum_total = 0
sum_total = 0
for num in numbers:
sum_total+=num
# C. Print the message "even" for each number that divides evenly by 2
# Hint: The modulus symbol, %, gives you the remainder when dividing two numbers
for num in numbers:
if num % 2 == 0:
print("even")
# D. Count how many even numbers there are by adding 1 to count for each even number
even_count = 0
even = 0
for num in range(1,20):
if num % 2 == 0:
even+=1
# Use list comprehension to generate new lists for these challenges
# A. Add "simon says " to all strings in this list
commands = ["jump", "duck", "touch your toes"]
commands = ["jump", "duck", "touch your toes"]
commands.append("simon says")
print(commands)
# B. Add 15% to each number above 100, and don't include other numbers
prices = [75, 500, 125, 20, 43]
prices = [75, 500, 125, 20, 43]
new = [price * 1.15 for price in prices]
round_new = [round(price,2) for price in new]
print(round_new)
# Use any variety of loop for the following challenges
# A. As a superfan, you want to chant each of the player's names in the following format:
# 1. Spell out their name with a separate print statement for each letter, followed by an exclamation point
# 2. Then, print the message "Goooo _______!" by inserting the full name in the blank
players = ["Anoushka", "Becky", "Mehreen"]
players = ["Anoushka", "Becky", "Mehreen"]
for pleyer in players:
for letter in player:
print(f"{letter}!", end=" ")
print(f"\n Goooo {player}! \n")
# B. Customers want to know the flavors of each coffee. Use separate print statements in the following format:
# First, print "_______ has the following flavors" using the coffee name in the blank
# Then, print each flavor inside the coffee's flavor list
coffee_blends = [
{"name": "Don Manuel", "flavors": ["cocoa", "lime", "cinnamon"]},
{"name": "Gitwe Washed", "flavors": ["grapefruit", "hibiscus", "honey"]}
]
coffee_blends = [
{"name": "Don Manuel", "flavors": ["cocoa", "lime", "cinnamon"]},
{"name": "Gitwe Washed", "flavors": ["grapefruit", "hibiscus", "honey"]}
]
for coffee in coffee_blends:
print(f"The coffee {coffee['name']} has the following flavors:")
for flavor in coffee["flavors"]:
print(f" - {flavor}")
# C. Shop till you've dropped 1000 dollars!
# Add each item to the purchases list until the total price exceeds 1000
store = [
{"item": "mountain bike", "price": 375},
{"item": "tambourine", "price": 50},
{"item": "massage chair", "price": 700},
{"item": "worlds best programmer mug", "price": 10},
{"item": "new computer", "price": 1500}
]
purchases = []
total_price = 0
store = [
{"item": "mountain bike", "price": 375},
{"item": "tambourine", "price": 50},
{"item": "massage chair", "price": 700},
{"item": "worlds best programmer mug", "price": 10},
{"item": "new computer", "price": 1500}
]
purchases = []
total_price = 0
items = 0
while total_price < 1001:
purchases.append(store[items])
total_price += store[items]["price"]
items += 1
print(items)