Skip to content

Learning Python: Day 17

Chapter 7 – User input and while loops How the input() function works parrot.py message = input(“Tell me something, and I will repeat it back to you: “) print(message) Tell me something, and I will repeat it back to you:… Read More »Learning Python: Day 17

Learning Python: Day 16

# Make an empty list for storing aliens. aliens = [] # Make 30 green aliens. for alien_number in range (30): ….new_alien = {‘color’: ‘green’, ‘points’: 5, ‘speed’: ‘slow’} ….aliens.append(new_alien) for alien in aliens[:3]: ….if alien[‘color’] == ‘green’: ……..alien[‘color’] =… Read More »Learning Python: Day 16

Learning Python: Day 15

Looping through a dictionary’s keys in a particular order favorite_languages = { …. ‘jen’: ‘python’, ….’sarah’: ‘c’, ….’edward’: ‘rust’, ….’phil’: ‘python’, ….} for name in sorted(favorite_languages.keys()): ….print(f”{name.title()}, thank you for taking the poll.”) Edward, thank you for taking the poll.… Read More »Learning Python: Day 15

Learning Python: Day 14

Looping through all the keys in a dictionary favorite_langueages = { ….’jen’: ‘python’, ….’sarah’: ‘c’, ….’edward’: ‘rust’, ….’phil’: ‘python’, ….} for name in favorite_languages.keys(): ….print(name.title()) Jen Sarah Edward Phil for name in favorite_languages: for name in favorite_languages.keys(): favorite_languages = {… Read More »Learning Python: Day 14

Learning Python: Day 13

Chapter 6 – Dictionaries A simple dictionary alien.py alien_0 = {‘color’: ‘green’, ‘points’: 5} print(alien_0[‘color’]) print(alien_0[‘points’]) green 5 Working with dictionaries alien_0 = {‘color’: ‘green’, ‘points’: 5} alien_0 = {‘color’: ‘green’} Accessing values in a dictionary alien.py alien_0 = {‘color’:… Read More »Learning Python: Day 13

Learning Python: Day 12

Checking that a list is not empty requested_toppings = [] if requested_toppings: ….for requested_topping in requested_toppings: ……..print(f”Adding {requested_topping}.”) ….print(“\nFinished making your pizza!”) else: ….print(“Are you sure you want a plain pizza?”) Are you sure you want a plain pizza? Using… Read More »Learning Python: Day 12

Learning Python: Day 11

Chapter 5 – If statements A simple example cars.py cars = [‘audi, ‘bmw’, subaru’, ‘toyota’] for car in cars: ….if car == ‘bmw’: ……..print(car.upper()) ….else: ….print(car.title()) Audi BMW Subaru Toyota Conditional tests Checking for equality >>> car = ‘bmw’ >>>… Read More »Learning Python: Day 11

Learning Python: Day 10

Styling your code The style guide Indentation Line length Blank lines Other style guides Summary End of study session.

Learning Python: Day 9

Copying a list foods.py my_foods = [‘pizza’, ‘falafel’, ‘carrot cake’] friends_foods = my_foods [:] print(“My favorite foods are:”) print(my_foods) print(“\nMy friend’s favorite foods are:”) print(friend_foods) My favorite foods are: [‘pizza’, ‘falafel’, ‘carrot cake’] My friend’s favorite foods are: [‘pizza’, ‘falafel’,… Read More »Learning Python: Day 9