├── Challenges ├── __init__.py ├── ChallengeSolutions │ ├── __init__.py │ ├── challenge_1_mad_libs.py │ ├── challenge_3e_word_guess_tests.py │ ├── challenge_2c_number_guess_with_for.py │ ├── challenge_2b_number_guess_with_while.py │ ├── challenge_2_number_guess.py │ ├── challenge_3b_word_guess_from_file.py │ ├── challenge_3c_word_guess_with_nested_functions.py │ ├── challenge_3e_word_guess_refactored.py │ ├── words.txt │ ├── challenge_3d_word_guess_with_classes.py │ └── challenge_3_word_guess.py ├── challenge_1_mad_libs.py ├── challenge_2_number_guess.py └── challenge_3_word_guess.py ├── Problems ├── __init__.py ├── Solutions │ ├── __init__.py │ ├── problem_2_happy_birthday.py │ ├── problem_7_new_years.py │ ├── problem_4_dice_roll.py │ ├── problem_3_temperature_converter.py │ ├── problem_8_for_bug.py │ ├── problem_1_equation_calculator.py │ ├── problem_5_circle_stats.py │ ├── problem_9_card_hands.py │ └── problem_6_lucky_number_guess.py ├── problem_2_happy_birthday.py ├── problem_7_new_years.py ├── problem_9_card_hands.py ├── problem_4_dice_roll.py ├── problem_3_temperature_converter.py ├── problem_8_for_bug.py ├── problem_1_equation_calculator.py ├── problem_5_circle_stats.py └── problem_6_lucky_number_guess.py ├── docs ├── img │ ├── installer_1.png │ ├── installer_2.png │ ├── installer_3.png │ ├── pycharm_python_1.png │ ├── pycharm_python_2.png │ ├── pycharm_python_3a.png │ ├── pycharm_python_3b.png │ ├── pycharm_python_4.png │ ├── pycharm_python_5a.png │ └── pycharm_python_5b.png ├── WININSTALL.md ├── PATH_LOCATIONS.md ├── WINSETPATH.md └── PyCharm_interpreter.md ├── Examples ├── example_4_syntax.py ├── example_7_math_comparisons.py ├── example_1_first_code.py ├── example_11_while_loops.py ├── example_6_string_methods.py ├── example_2_types.py ├── example_9_other_comparisons.py ├── example_13_for_loops.py ├── example_3_variables.py ├── example_8_boolean_comparisons.py ├── example_5_functions.py ├── example_10_if_else.py └── example_12_lists.py ├── .gitignore └── README.md /Challenges/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Problems/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Problems/Solutions/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Challenges/ChallengeSolutions/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/img/installer_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ariannedee/intro-to-python/HEAD/docs/img/installer_1.png -------------------------------------------------------------------------------- /docs/img/installer_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ariannedee/intro-to-python/HEAD/docs/img/installer_2.png -------------------------------------------------------------------------------- /docs/img/installer_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ariannedee/intro-to-python/HEAD/docs/img/installer_3.png -------------------------------------------------------------------------------- /Problems/problem_2_happy_birthday.py: -------------------------------------------------------------------------------- 1 | """ 2 | Ask for the user's name and then sing happy birthday to them. 3 | """ 4 | -------------------------------------------------------------------------------- /docs/img/pycharm_python_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ariannedee/intro-to-python/HEAD/docs/img/pycharm_python_1.png -------------------------------------------------------------------------------- /docs/img/pycharm_python_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ariannedee/intro-to-python/HEAD/docs/img/pycharm_python_2.png -------------------------------------------------------------------------------- /docs/img/pycharm_python_3a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ariannedee/intro-to-python/HEAD/docs/img/pycharm_python_3a.png -------------------------------------------------------------------------------- /docs/img/pycharm_python_3b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ariannedee/intro-to-python/HEAD/docs/img/pycharm_python_3b.png -------------------------------------------------------------------------------- /docs/img/pycharm_python_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ariannedee/intro-to-python/HEAD/docs/img/pycharm_python_4.png -------------------------------------------------------------------------------- /docs/img/pycharm_python_5a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ariannedee/intro-to-python/HEAD/docs/img/pycharm_python_5a.png -------------------------------------------------------------------------------- /docs/img/pycharm_python_5b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ariannedee/intro-to-python/HEAD/docs/img/pycharm_python_5b.png -------------------------------------------------------------------------------- /Problems/problem_7_new_years.py: -------------------------------------------------------------------------------- 1 | """ 2 | Start at 10 seconds and count down until 1 and then print "Happy New Year! 🎉" 3 | """ 4 | 5 | print('Happy New Year! 🎉') 6 | -------------------------------------------------------------------------------- /Problems/problem_9_card_hands.py: -------------------------------------------------------------------------------- 1 | """ 2 | Deal a hand of 5 cards 3 | """ 4 | 5 | suits = ['♠︎', '♣︎', '♥︎', '♦︎'] 6 | values = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'] 7 | 8 | cards = [] 9 | hand = [] 10 | 11 | 12 | print(hand) 13 | -------------------------------------------------------------------------------- /Problems/problem_4_dice_roll.py: -------------------------------------------------------------------------------- 1 | """ 2 | Randomly returns two numbers between 1 and 6 3 | """ 4 | 5 | # Generate two random integer between 1 and 6 (inclusive) 6 | die1 = None 7 | die2 = None 8 | 9 | # Tell the user what the result was 10 | print("You rolled a {} and a {} (total {})") 11 | -------------------------------------------------------------------------------- /Challenges/challenge_1_mad_libs.py: -------------------------------------------------------------------------------- 1 | # Write a story with some words missing 2 | story = """ 3 | Roses are {colour} 4 | Violets are {colour2} 5 | Sugar is {adjective} 6 | And so are you 7 | """ 8 | 9 | # Ask the user to provide the missing words 10 | 11 | 12 | # Display the final story 13 | print(story) 14 | -------------------------------------------------------------------------------- /Problems/Solutions/problem_2_happy_birthday.py: -------------------------------------------------------------------------------- 1 | """ 2 | Ask for the user's name and then sing happy birthday to them. 3 | """ 4 | 5 | name = input("Who's birthday is it? ") 6 | 7 | print('Happy birthday to you') 8 | print('Happy birthday to you') 9 | print('Happy birthday dear ' + name) 10 | print('Happy birthday to you') 11 | -------------------------------------------------------------------------------- /Problems/Solutions/problem_7_new_years.py: -------------------------------------------------------------------------------- 1 | """ 2 | Start at 10 seconds and count down until 1 and then print "Happy New Year! 🎉" 3 | """ 4 | import time 5 | 6 | seconds_left = 10 7 | 8 | while seconds_left > 0: 9 | print(seconds_left) 10 | seconds_left -= 1 11 | time.sleep(1) 12 | 13 | print('Happy New Year! 🎉') 14 | -------------------------------------------------------------------------------- /Problems/problem_3_temperature_converter.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given a temperature in Fahrenheit, return the temperature in Celsius 3 | """ 4 | # Ask for a temperature in Fahrenheit 5 | temp_f = input("Temp in °F: ") 6 | 7 | # Calculate it in Celsius 8 | temp_c = None 9 | 10 | # Tell the user what it is 11 | print("Temp in °C: " + temp_c) 12 | -------------------------------------------------------------------------------- /Problems/Solutions/problem_4_dice_roll.py: -------------------------------------------------------------------------------- 1 | """ 2 | Randomly returns two numbers between 1 and 6 3 | """ 4 | import random 5 | 6 | # Generate two random integer between 1 and 6 (inclusive) 7 | die_1 = random.randint(1, 6) 8 | die_2 = random.randint(1, 6) 9 | 10 | # Tell the user what the result was 11 | print(f'You rolled a {die_1} and {die_2}') 12 | -------------------------------------------------------------------------------- /Examples/example_4_syntax.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | number = random.randint(1, 11) 4 | guess = int(input('Guess a number between 1 and 10: ')) 5 | 6 | if guess == number: 7 | print(f"You're right! it was {number}") 8 | elif guess - 2 <= number <= guess + 2: 9 | print(f"Close! It's {number}") 10 | else: 11 | print(f"Nope, it's {number}") 12 | -------------------------------------------------------------------------------- /Problems/Solutions/problem_3_temperature_converter.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given a temperature in Fahrenheit, return the temperature in Celsius 3 | """ 4 | # Ask for a temperature in Fahrenheit 5 | temp_in_f = float(input('Temp in F: ')) 6 | 7 | # Calculate it in Celsius 8 | temp_in_c = (temp_in_f - 32) * 5/9 9 | 10 | # Tell the user what it is 11 | print('Temp in C: {}'.format(temp_in_c)) 12 | -------------------------------------------------------------------------------- /Problems/problem_8_for_bug.py: -------------------------------------------------------------------------------- 1 | """ 2 | This code should request a word from the user and return how many vowels that 3 | word contains. 4 | 5 | Find the bug. 6 | """ 7 | 8 | word = input("Type a word: ") 9 | num_vowels = 0 10 | 11 | for letter in word: 12 | if letter in word: 13 | num_vowels += 1 14 | 15 | print('There are {} vowels in "{}"'.format(num_vowels, word)) 16 | -------------------------------------------------------------------------------- /Problems/problem_1_equation_calculator.py: -------------------------------------------------------------------------------- 1 | """ 2 | Calculate the gravitational force between Earth and Venus 3 | """ 4 | 5 | G = 6.67e-11 # Gravitational constant 6 | 7 | mass_1 = 6e24 # in kg (mass of Earth) 8 | mass_2 = 4.9e24 # in kg (mass of Venus) 9 | distance = 4.1e10 # in m (distance between Earth and Venus) 10 | 11 | force = None # <-- Replace with your code 12 | 13 | print(force) 14 | -------------------------------------------------------------------------------- /Problems/Solutions/problem_8_for_bug.py: -------------------------------------------------------------------------------- 1 | """ 2 | This code should request a word from the user and return how many vowels that 3 | word contains. 4 | 5 | Find the bug. 6 | """ 7 | 8 | word = input("Type a word: ") 9 | num_vowels = 0 10 | 11 | for letter in word.lower(): 12 | if letter in 'aeiou': 13 | num_vowels += 1 14 | 15 | print('There are {} vowels in "{}"'.format(num_vowels, word)) 16 | -------------------------------------------------------------------------------- /Problems/Solutions/problem_1_equation_calculator.py: -------------------------------------------------------------------------------- 1 | """ 2 | Calculate the gravitational force between Earth and Venus 3 | """ 4 | 5 | G = 6.67e-11 # Gravitational constant 6 | 7 | mass_1 = 6e24 # in kg (mass of Earth) 8 | mass_2 = 4.9e24 # in kg (mass of Venus) 9 | distance = 4.1e10 # in m (distance between Earth and Venus) 10 | 11 | force = (G * mass_1 * mass_2) / (distance**2) 12 | 13 | print(force) 14 | -------------------------------------------------------------------------------- /Problems/Solutions/problem_5_circle_stats.py: -------------------------------------------------------------------------------- 1 | """ 2 | Fill out the functions to calculate the area and circumference of a circle. 3 | Print the result to the user. 4 | """ 5 | from math import pi 6 | 7 | 8 | def area(r): 9 | return pi * r**2 10 | 11 | 12 | def circumference(r): 13 | return 2*pi*r 14 | 15 | 16 | radius = float(input("Circle radius: ")) 17 | 18 | print(f'Area: {area(radius)}') 19 | print(f'Circumference: {circumference(radius)}') 20 | -------------------------------------------------------------------------------- /Problems/problem_5_circle_stats.py: -------------------------------------------------------------------------------- 1 | """ 2 | Fill out the functions to calculate the area and circumference of a circle. 3 | Print the result to the user. 4 | """ 5 | 6 | 7 | def area(r): 8 | ... 9 | 10 | 11 | def circumference(r): 12 | ... 13 | 14 | 15 | radius = input("Circle radius: ") 16 | 17 | print('Area: {}') # <-- Call the area function and print the result 18 | print('Circumference: {}') # <-- Call the circumference function and print 19 | -------------------------------------------------------------------------------- /Examples/example_7_math_comparisons.py: -------------------------------------------------------------------------------- 1 | x = 5 2 | print(f'x == 5 is {x == 5}') 3 | print(f'x == -5 is {x == -5}') 4 | print(f'x != 5 is {x != 5}') 5 | print(f'x != -5 is {x != -5}') 6 | print(f'x > 4 is {x > 4}') 7 | print(f'x > 5 is {x > 5}') 8 | print(f'x >= 5 is {x >= 5}') 9 | print(f'x < 6 is {x < 6}') 10 | print(f'x < 5 is {x < 5}') 11 | print(f'x <= 5 is {x <= 5}') 12 | print(f'0 <= x <= 5 is {0 <= x <= 5}') 13 | print(f'x < 0 or x > 100 is {x < 0 or x > 100}') 14 | -------------------------------------------------------------------------------- /Examples/example_1_first_code.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | 4 | print('hello world') 5 | 6 | print("hello world") 7 | 8 | print('hello \n world') 9 | 10 | name = 'world' 11 | print(f'hello {name}') 12 | 13 | print(2 + 2) 14 | 15 | print(123 * 456) 16 | 17 | print(1/2) 18 | 19 | print(-123/456) 20 | 21 | print(5 % 2) 22 | 23 | print(6 % 2) 24 | 25 | print(7 % 2) 26 | 27 | print(3**3) 28 | 29 | print(math.e) 30 | 31 | print(math.pi) 32 | 33 | print(math.log(100, 10)) 34 | -------------------------------------------------------------------------------- /Challenges/ChallengeSolutions/challenge_1_mad_libs.py: -------------------------------------------------------------------------------- 1 | # Write a story with some words missing 2 | story = ''' 3 | Roses are {colour} 4 | Violets are {colour2} 5 | Sugar is {taste} 6 | And so are you 7 | ''' 8 | 9 | # Ask the user to provide the missing words 10 | colour = input('Give me a colour: ') 11 | colour2 = input('Give me another colour: ') 12 | taste = input('Give me a flavour: ') 13 | 14 | # Display the final story 15 | print(story.format(colour=colour, colour2=colour2, taste=taste)) 16 | -------------------------------------------------------------------------------- /Problems/Solutions/problem_9_card_hands.py: -------------------------------------------------------------------------------- 1 | """ 2 | Deal a hand of 5 cards 3 | """ 4 | import random 5 | 6 | suits = ['♠︎', '♣︎', '♥︎', '♦︎'] 7 | values = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'] 8 | 9 | cards = [] 10 | hand = [] 11 | 12 | for suit in suits: 13 | for value in values: 14 | cards.append(suit + value) 15 | 16 | for num in range(5): 17 | card = random.choice(cards) 18 | hand.append(card) 19 | cards.remove(card) 20 | 21 | print(hand) 22 | -------------------------------------------------------------------------------- /Examples/example_11_while_loops.py: -------------------------------------------------------------------------------- 1 | x = 3 2 | 3 | while x >= 0: # Will keep looping until condition is False 4 | print(x) 5 | x = x - 1 6 | 7 | 8 | y = 0 9 | while True: # Will keep looping until it encounters a break 10 | print(y) 11 | y += 1 12 | if y == 10: 13 | break 14 | 15 | 16 | z = 10 17 | while z > 0: 18 | z -= 1 19 | if z % 2 == 1: # If z is odd (remainder of z / 2 is 1) 20 | continue # Stop current loop (don't print) but go onto the next iteration 21 | print(z) 22 | -------------------------------------------------------------------------------- /Examples/example_6_string_methods.py: -------------------------------------------------------------------------------- 1 | string = 'Hello world' 2 | 3 | print(string.upper()) 4 | print(string.lower()) 5 | print(string.title()) 6 | 7 | print(string[0]) 8 | print(string[-1]) 9 | print(string[0:4]) 10 | print(string[5:]) 11 | print(string[::2]) 12 | print(string[::-1]) 13 | print(len(string)) 14 | 15 | string = ' Hello world ' 16 | print(string.strip()) 17 | print(string.capitalize()) 18 | print(string.strip().capitalize()) 19 | 20 | string_list = string.split() 21 | print(string_list) 22 | print('*'.join(string_list)) 23 | -------------------------------------------------------------------------------- /Examples/example_2_types.py: -------------------------------------------------------------------------------- 1 | print(type(1)) 2 | print(type(3.14)) 3 | print(type('papaya')) 4 | print(type(True)) 5 | print(type(False)) 6 | print(type(None)) 7 | print(type([1, 2, 10])) 8 | print(type({'apple': 'A round fruit', 'banana': 'A long yellow fruit', 9 | 'cucumber': 'A long green fruit'})) 10 | 11 | print(int('1')) 12 | print(float('1')) 13 | print(bool('1')) 14 | print(str(1)) 15 | 16 | print(isinstance(1, int)) 17 | print(isinstance(1, float)) 18 | print(isinstance(1, (int, float))) 19 | print(isinstance('1', (int, float))) 20 | -------------------------------------------------------------------------------- /Examples/example_9_other_comparisons.py: -------------------------------------------------------------------------------- 1 | print(f"'i' in 'team' is {'i' in 'team'}") 2 | print(f"'i' in 'win' is {'i' in 'win'}") 3 | 4 | print(f'isinstance(10, int) is {isinstance(10, int)}') 5 | print(f'isinstance(10.0, int) is {isinstance(10.0, int)}') 6 | 7 | print(f"'HELLO'.isupper() is {'HELLO'.isupper()}") 8 | print(f"'pAssW0rD1'.isalnum() is {'pAssW0rD1'.isalnum()}") 9 | print(f"'pAssW0rD1'.isalpha() is {'pAssW0rD1'.isalpha()}") 10 | 11 | print(f"'3.14'.isnumeric() is {'3.14'.isnumeric()}") 12 | print(f"'1400'.isnumeric() is {'1400'.isnumeric()}") 13 | -------------------------------------------------------------------------------- /Challenges/challenge_2_number_guess.py: -------------------------------------------------------------------------------- 1 | """ 2 | Number guessing game 3 | The number to guess will be from 1 to 20 (inclusive). 4 | The user will have 4 guesses to guess the number correctly. 5 | After each wrong guess, the user will be told whether to 6 | guess higher or lower next time. 7 | If the user doesn't win, tell them the number. 8 | """ 9 | import random 10 | 11 | 12 | def run_game(): 13 | answer = random.randint(1, 20) 14 | 15 | print("I'm thinking of a number between 1 and 20") 16 | 17 | guess = int(input("Guess a number: ")) 18 | 19 | 20 | run_game() 21 | -------------------------------------------------------------------------------- /Examples/example_13_for_loops.py: -------------------------------------------------------------------------------- 1 | # Use range(start, stop, step=1) to loop through a list of numbers 2 | for i in range(10): 3 | print(i) 4 | print() 5 | 6 | for i in range(10, 20): 7 | print(i) 8 | print() 9 | 10 | for i in range(10, 20, 2): 11 | print(i) 12 | print() 13 | 14 | 15 | primes = [1, 2, 3, 5, 7, 11, 13] 16 | # Can loop over lists 17 | for number in primes: 18 | print(f'The square of {number} is {number ** 2}') 19 | 20 | 21 | # If you need to know the index, use enumerate() 22 | for i, number in enumerate(primes): 23 | print(f'{i}: {number}') 24 | -------------------------------------------------------------------------------- /Problems/problem_6_lucky_number_guess.py: -------------------------------------------------------------------------------- 1 | """ 2 | This code should get the user to guess a random number between 1 and 10. 3 | If the user is right, congratulate them. 4 | If they're wrong, say if the answer is higher or lower. 5 | Then say what the answer was. 6 | """ 7 | 8 | import random 9 | answer = random.randint(1, 10) 10 | 11 | guess = int(input("I'm thinking of a number between 1 and 10: ")) 12 | 13 | # If the number is correct, tell the user 14 | # Otherwise, tell them if the answer is higher or lower than their guess 15 | 16 | 17 | print('The number was {}'.format(answer)) 18 | -------------------------------------------------------------------------------- /Problems/Solutions/problem_6_lucky_number_guess.py: -------------------------------------------------------------------------------- 1 | """ 2 | This code should get the user to guess a random number between 1 and 10. 3 | If the user is right, congratulate them. 4 | If they're wrong, say if the answer is higher or lower. 5 | Then say what the answer was. 6 | """ 7 | 8 | import random 9 | answer = random.randint(1, 10) 10 | 11 | guess = int(input("I'm thinking of a number between 1 and 10: ")) 12 | 13 | if guess == answer: 14 | print('Correct!') 15 | elif guess < answer: 16 | print('Higher') 17 | else: 18 | print('Lower') 19 | 20 | print('The number was {}'.format(answer)) 21 | -------------------------------------------------------------------------------- /Examples/example_3_variables.py: -------------------------------------------------------------------------------- 1 | num_coconuts = 0 2 | print('I have ' + str(num_coconuts) + ' coconuts') 3 | 4 | num_coconuts = 5 5 | print('I bought 5 coconuts and now have ' + str(num_coconuts)) 6 | 7 | num_coconuts += 10 8 | print('I was given 10 coconuts and now I have ' + str(num_coconuts)) 9 | 10 | num_coconuts -= 8 11 | print('I gave 8 coconuts away and now I have ' + str(num_coconuts)) 12 | 13 | num_coconuts = 'banana' 14 | print('My coconuts turned into ' + num_coconuts) 15 | 16 | num_bananas = 3 17 | print('What is happening to my coconuts? ' + num_coconuts*num_bananas) 18 | 19 | del num_coconuts 20 | print('My coconuts don\'t exist anymore ' + str(num_coconuts)) 21 | -------------------------------------------------------------------------------- /Examples/example_8_boolean_comparisons.py: -------------------------------------------------------------------------------- 1 | print(f'True and True is {True and True}') 2 | print(f'True and False is {True and False}') 3 | print(f'False and False is {False and False}') 4 | print() 5 | print(f'True or True is {True or True}') 6 | print(f'True or False is {True or False}') 7 | print(f'False or False is {False or False}') 8 | print() 9 | print(f'not True is {not True}') 10 | print(f'not False is {not False}') 11 | print() 12 | 13 | print(f'True and not True is {True and not True}') # Always False 14 | print(f'True or not True is {True or not True}') # Always True 15 | 16 | rain = True 17 | snow = False 18 | print((rain and snow) or (not rain and not snow)) # Use brackets to group 19 | -------------------------------------------------------------------------------- /Examples/example_5_functions.py: -------------------------------------------------------------------------------- 1 | def add(a, b): 2 | a = float(a) 3 | b = float(b) 4 | return a + b 5 | 6 | 7 | print(add(1, 2)) 8 | print(add('1', '2')) 9 | 10 | 11 | def say_hello(name, shout=False): # Can have optional parameters (e.g. shout) 12 | greeting = 'Hello ' + name 13 | if shout: 14 | greeting = greeting.upper() 15 | return greeting 16 | 17 | 18 | print(say_hello('beyoncé')) # 1 required argument 19 | print(say_hello('beyoncé', True)) # Positional arguments 20 | print(say_hello('beyoncé', shout=False)) # Positional has to come before keyword arguments 21 | print(say_hello(shout=True, name='beyoncé')) # Keyword args can be in any order 22 | -------------------------------------------------------------------------------- /Challenges/ChallengeSolutions/challenge_3e_word_guess_tests.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests some of the functions in word_guessing_game 3 | Look into unittest, pytest, and mock libraries for more advanced tests 4 | """ 5 | from .challenge_3e_word_guess_refactored import ( 6 | display_word, 7 | game_won, 8 | guess_is_correct 9 | ) 10 | 11 | 12 | assert display_word('hello', []) == '_ _ _ _ _' 13 | assert display_word('hello', ['l']) == '_ _ l l _' 14 | assert display_word('hello', ['e', 'h', 'o', 'l']) == 'h e l l o' 15 | 16 | 17 | assert not game_won('hello', []) 18 | assert not game_won('hello', ['h', 'a', 'e', 'l', 'b']) 19 | assert game_won('hello', ['h', 'a', 'e', 'l', 'b', 'o']) 20 | assert game_won('', []) 21 | 22 | 23 | assert not guess_is_correct('a', 'hello') 24 | assert guess_is_correct('e', 'hello') 25 | -------------------------------------------------------------------------------- /docs/WININSTALL.md: -------------------------------------------------------------------------------- 1 | ## Installing Python on Windows 2 | The Python installer for Windows doesn't use the optimal default settings. 3 | Follow these instructions when running the installer. 4 | If you have already installed Python with the default settings, 5 | follow the instructions here instead: [add Python to the PATH variable](WINSETPATH.md) 6 | 7 | 1. Check the *Add Python to PATH* box 8 | 2. Choose the *Customize installation* option 9 | 10 | 11 | 3. Keep the default settings and click *Next* 12 | 13 | 14 | 4. Check the *Install for all users* box 15 | 5. Customize the install location: **C:\Python39** or whatever version number you're installing 16 | 6. Click *Install* 17 | 18 | -------------------------------------------------------------------------------- /Challenges/ChallengeSolutions/challenge_2c_number_guess_with_for.py: -------------------------------------------------------------------------------- 1 | """ 2 | Number guessing game 3 | The number to guess will be from 1 to 20 (inclusive). 4 | The user will have 4 guesses to guess the number correctly. 5 | After each wrong guess, the user will be told whether to 6 | guess higher or lower next time. 7 | If the user doesn't win, tell them the number. 8 | """ 9 | import random 10 | 11 | 12 | def run_game(): 13 | # Write code here 14 | answer = random.randint(1, 20) 15 | guess = int(input("guess a number between 1 and 20: ")) 16 | 17 | for i in range(4): 18 | if guess == answer: 19 | print("That's right!") 20 | break 21 | if guess < answer: 22 | print("Higher") 23 | else: 24 | print("Lower") 25 | print('You have {} guesses left'.format(4-i)) 26 | 27 | guess = int(input("guess a number between 1 and 20: ")) 28 | 29 | print("the answer is {}".format(answer)) 30 | 31 | 32 | run_game() 33 | -------------------------------------------------------------------------------- /Examples/example_10_if_else.py: -------------------------------------------------------------------------------- 1 | salutation = 'Hello world' 2 | shouting = False 3 | 4 | if shouting: 5 | print(salutation.upper()) 6 | else: 7 | print(salutation) 8 | 9 | 10 | hungry = True 11 | 12 | if hungry: # else is not needed 13 | print('Find something to eat') 14 | print('Continue your day') 15 | 16 | 17 | temp = int(input("What temperature is your water? ")) 18 | 19 | if temp <= 0: 20 | print("It's freezing") 21 | elif temp >= 100: # Can have multiple elif (else if) 22 | print("It's boiling") 23 | elif temp >= 50: 24 | print("It's hot") 25 | else: 26 | print("It's just water") 27 | 28 | print("Another") 29 | 30 | # Conditions don't have to be True or False 31 | name = input("Name: ") 32 | 33 | if name: # Will evaluate bool(name) 34 | print("Hello " + name) 35 | else: 36 | print("Hello world") 37 | 38 | 39 | # Comparing to True, False and None should use "is" keyword 40 | name_was_input = bool(name) 41 | 42 | if name_was_input is False: 43 | print("Invalid name") 44 | -------------------------------------------------------------------------------- /Examples/example_12_lists.py: -------------------------------------------------------------------------------- 1 | # Indexing and slicing 2 | new_list = [0, 1, 2, 3] 3 | 4 | print(new_list[1]) # First item 5 | print(new_list[-1]) # Last item 6 | print(new_list[1:3]) 7 | print(new_list[:2]) 8 | print(new_list[2:]) 9 | print(new_list[::2]) 10 | print(new_list[::-1]) 11 | print() 12 | 13 | 14 | # Adding, removing, and updating 15 | languages = ['English', 'French', 'Mandarin'] 16 | 17 | languages[0] = 'Icelandic' 18 | del languages[1] 19 | languages.append('Tagalog') # Adds item to end of list 20 | languages.insert(1, 'Spanish') # Adds item to list at index 21 | languages.remove('Mandarin') 22 | print(languages) 23 | 24 | 25 | # More list methods 26 | new_list.insert(1, True) # Lists can hold any type of data 27 | new_list.extend([1, 2, 3]) 28 | print(new_list) 29 | new_list.reverse() 30 | print(new_list) 31 | print(new_list.count(1)) # Remember, 1 == True 32 | new_list.sort() 33 | print(new_list) 34 | 35 | 36 | # Nested lists can be used for matrices 37 | matrix = [[1, 2, 3], 38 | [4, 5, 6], 39 | [7, 8, 9]] 40 | 41 | matrix[1][0] = 1000 42 | print(matrix) 43 | -------------------------------------------------------------------------------- /docs/PATH_LOCATIONS.md: -------------------------------------------------------------------------------- 1 | # Locating Python on your computer 2 | If you are trying to find the location of Python3 on your computer, 3 | try these locations first. 4 | The exact location and filename will depend 5 | on the method you used to install Python 6 | and which version is installed. 7 | 8 | ## Windows 9 | Look for `python.exe` 10 | - C:\Python39 11 | - C:\Program Files\Python39 12 | - C:\Users\\*username*\AppData\Local\Programs\Python\Python39-XX 13 | 14 | ## Mac 15 | Look for `python3.9` or `python3` 16 | 17 | - /usr/local/bin 18 | - /Library/Frameworks/Python.framework/Versions/3.9/bin/ 19 | - /usr/local/Cellar/python/3.9.X_X/bin/ 20 | - /Users/*username*/anaconda/bin/ 21 | - /anaconda3/bin/ 22 | 23 | ## Linux 24 | Look for `python3.9` or `python3` 25 | - /usr/bin/ 26 | - /usr/local/bin 27 | 28 | ### Finally 29 | If you didn't find it at any of these locations, 30 | try searching google more specifically based on 31 | your Python version, operating system, and method of download. 32 | 33 | If you found it at another location, please email me at 34 | **arianne.dee.studios@gmail.com** so I can update this list. 35 | -------------------------------------------------------------------------------- /Challenges/ChallengeSolutions/challenge_2b_number_guess_with_while.py: -------------------------------------------------------------------------------- 1 | """ 2 | Number guessing game 3 | The number to guess will be from 1 to 20 (inclusive). 4 | The user will have 3 guesses to guess the number correctly. 5 | After each wrong guess, the user will be told whether to 6 | guess higher or lower next time. 7 | If the user doesn't win, tell them the number. 8 | """ 9 | import random 10 | 11 | 12 | def run_game(): 13 | number = random.randint(1, 20) 14 | max_guesses = 4 15 | current_guess = 0 16 | 17 | print("I'm thinking of a number between 1 and 20") 18 | 19 | while True: 20 | guess = int(input("Guess a number: ")) 21 | current_guess += 1 22 | if guess == number: 23 | print("That's right!") 24 | return 25 | elif current_guess == max_guesses: 26 | print("Nope! It was " + str(number)) 27 | return 28 | elif number < guess: 29 | print("Lower") 30 | else: 31 | print("Higher") 32 | print('You have {} guesses left'.format(max_guesses - current_guess)) 33 | 34 | 35 | run_game() 36 | -------------------------------------------------------------------------------- /docs/WINSETPATH.md: -------------------------------------------------------------------------------- 1 | ## Windows set up instruction 2 | If you installed Python with the default options, 3 | you will probably need to add Python to the PATH variable. 4 | This let's your operating system know where to look for the Python executable 5 | when you try running it. 6 | 7 | To add Python to your PATH variable: 8 | 1. Find the path of **python.exe** on your system. 9 | [Look in these directories](PATH_LOCATIONS.md) or search for it. 10 | 11 | 1. Open *System Properties* and click on the *Advanced* tab 12 | 13 | 1. Click on *Environment Variables* 14 | 15 | 1. Under *System variables* find and click on the *Path* variable 16 | 17 | 1. In edit mode, go to the end of the line and add **;C:\Python38** or whatever folder *python.exe* is in. 18 | Note the semicolon before the path; this will separate it from the previous path. 19 | 20 | To check that the PATH variable was set properly: 21 | 1. Open the *Command Prompt* application in Windows 22 | or *Terminal* on Mac or Linux 23 | 24 | 1. Type `python --version` and press enter 25 | 26 | 1. Type `python3 --version` and press enter 27 | 28 | 1. Type `py --version` and press enter (Windows) 29 | 30 | 1. At least one of these commands should print 31 | a Python version of 3.6 or higher 32 | (whichever version you just downloaded) 33 | 34 | If you are having problems: 35 | 36 | Search the internet for "**Add python to path on Windows *10 / Vista / XP / etc***" 37 | to find instructions for your version of Windows. 38 | -------------------------------------------------------------------------------- /Challenges/ChallengeSolutions/challenge_2_number_guess.py: -------------------------------------------------------------------------------- 1 | """ 2 | Number guessing game 3 | The number to guess will be from 1 to 20 (inclusive). 4 | The user will have 4 guesses to guess the number correctly. 5 | After each wrong guess, the user will be told whether to 6 | guess higher or lower next time. 7 | If the user doesn't win, tell them the number. 8 | """ 9 | import random 10 | 11 | 12 | def run_game(): 13 | number = random.randint(1, 20) 14 | 15 | print("I'm thinking of a number between 1 and 20") 16 | print('You have 4 guesses left') 17 | 18 | guess = int(input("Guess a number: ")) 19 | if guess == number: 20 | print("That's right!") 21 | return 22 | elif number < guess: 23 | print("Lower") 24 | else: 25 | print("Higher") 26 | 27 | print('You have 3 guesses left') 28 | guess = int(input("Guess a number: ")) 29 | if guess == number: 30 | print("That's right!") 31 | return 32 | elif number < guess: 33 | print("Lower") 34 | else: 35 | print("Higher") 36 | 37 | print('You have 2 guesses left') 38 | guess = int(input("Guess a number: ")) 39 | if guess == number: 40 | print("That's right!") 41 | return 42 | elif number < guess: 43 | print("Lower") 44 | else: 45 | print("Higher") 46 | 47 | print('You have 1 guess left') 48 | guess = int(input("Guess a number: ")) 49 | if guess == number: 50 | print("That's right!") 51 | return 52 | print("Nope! It was " + str(number)) 53 | 54 | 55 | run_game() 56 | -------------------------------------------------------------------------------- /docs/PyCharm_interpreter.md: -------------------------------------------------------------------------------- 1 | # Configuring your Python virtual environment PyCharm (Community and Pro) 2 | 3 | ## 1. Open your settings/preferences 4 | 5 | 6 | 7 | ## 2. Navigate to the Project Interpreter 8 | 9 | 10 | 11 | ## 3a. Select an existing interpreter 12 | 13 | 14 | 15 | If your desired version was found, click OK. If not, go on to 3b. 16 | 17 | ## 3b. Add a new interpreter 18 | 19 | 20 | 21 | ## 4. Add a system interpreter 22 | 23 | 24 | ## 5a. Select an existing system interpreter 25 | 26 | 27 | 28 | If your desired version was found, click OK. If not, go on to 5b. 29 | 30 | ## 5b. Find your system interpreter 31 | 32 | 33 | 34 | If you’re not sure where to find it, try one of the following locations 35 | (replace 3.9 or 39 with the desired version number): 36 | 37 | ### Windows (look for python.exe) 38 | - C:\Python39 39 | - C:\Program Files\Python39 40 | - C:\Users\username\AppData\Local\Programs\Python\Python39-XX 41 | 42 | ### Mac (look for python3.9 or python3) 43 | - /usr/local/bin/ 44 | - /Library/Frameworks/Python.framework/Versions/3.9/bin/ 45 | - /usr/local/Cellar/python/3.9.X_X/bin/ 46 | - /Users/username/anaconda/bin/ 47 | - /anaconda3/bin/ 48 | 49 | ### Linux (look for python3.9 or python3) 50 | - /usr/bin/ 51 | - /usr/local/bin -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | 106 | .DS_Store 107 | .idea -------------------------------------------------------------------------------- /Challenges/ChallengeSolutions/challenge_3b_word_guess_from_file.py: -------------------------------------------------------------------------------- 1 | """ 2 | Refactored word guessing game that gets a random word from the file 'words.txt' 3 | """ 4 | import random 5 | 6 | 7 | def display_word(word, guessed_letters): 8 | displayed_word = '' 9 | for letter in word: 10 | if letter in guessed_letters: 11 | displayed_word += letter 12 | else: 13 | displayed_word += '_' 14 | displayed_word += ' ' 15 | return displayed_word 16 | 17 | 18 | def guess_is_correct(guess, word): 19 | return guess in word 20 | 21 | 22 | def game_won(word, guessed_letters): 23 | for letter in word: 24 | if letter not in guessed_letters: 25 | return False 26 | return True 27 | 28 | 29 | def game_lost(guesses_left): 30 | return guesses_left == 0 31 | 32 | 33 | def word_game(word): 34 | word = word.lower() 35 | guessed_letters = [] 36 | wrong_guesses_left = 6 37 | 38 | while True: 39 | # Display current state of the game 40 | print(display_word(word, guessed_letters)) 41 | print(f'Guessed letters: {" ".join(guessed_letters)}') 42 | print(f'Guesses left: {wrong_guesses_left}\n') 43 | 44 | # Get a guess from the user 45 | guess = input('Guess a letter: ') 46 | print() 47 | 48 | # Handle the user's guess 49 | guessed_letters.append(guess) 50 | if guess_is_correct(guess, word): 51 | print('Correct!') 52 | else: 53 | wrong_guesses_left -= 1 54 | print('Nope!') 55 | 56 | # Check to see if they won or lost 57 | if game_won(word, guessed_letters): 58 | print(f'You won :) The word was "{word}"') 59 | return 60 | elif game_lost(wrong_guesses_left): 61 | print(f'You lost :( The word was "{word}"') 62 | return 63 | 64 | 65 | with open('words.txt', 'r') as file: 66 | words = file.readlines() 67 | answer = random.choice(words).strip() 68 | 69 | word_game(answer) 70 | -------------------------------------------------------------------------------- /Challenges/ChallengeSolutions/challenge_3c_word_guess_with_nested_functions.py: -------------------------------------------------------------------------------- 1 | """ 2 | Word guess game refactored so to use nested functions. 3 | The inner functions can use variables from the outer function's scope. 4 | You no longer have to pass 'word' and 'guessed_letters' around. 5 | """ 6 | import random 7 | 8 | 9 | def word_game(word): 10 | word = word.lower() 11 | guessed_letters = [] 12 | wrong_guesses_left = 6 13 | 14 | def display_word(): 15 | displayed_word = '' 16 | for letter in word: 17 | if letter in guessed_letters: 18 | displayed_word += letter 19 | else: 20 | displayed_word += '_' 21 | displayed_word += ' ' 22 | return displayed_word 23 | 24 | def guess_is_correct(letter): 25 | return letter in word 26 | 27 | def game_won(): 28 | for letter in word: 29 | if letter not in guessed_letters: 30 | return False 31 | return True 32 | 33 | def game_lost(): 34 | return wrong_guesses_left == 0 35 | 36 | while True: 37 | # Display current state of the game 38 | print(display_word()) 39 | print(f'Guessed letters: {" ".join(guessed_letters)}') 40 | print(f'Guesses left: {wrong_guesses_left}\n') 41 | 42 | # Get a guess from the user 43 | guess = input('Guess a letter: ') 44 | print() 45 | 46 | # Handle the user's guess 47 | guessed_letters.append(guess) 48 | if guess_is_correct(guess): 49 | print('Correct!') 50 | else: 51 | wrong_guesses_left -= 1 52 | print('Nope!') 53 | 54 | # Check to see if they won or lost 55 | if game_won(): 56 | print(f'You won :) The word was "{word}"') 57 | return 58 | elif game_lost(): 59 | print(f'You lost :( The word was "{word}"') 60 | return 61 | 62 | 63 | # Choose a random word 64 | with open('words.txt', 'r') as file: 65 | words = file.readlines() 66 | answer = random.choice(words).strip() 67 | 68 | word_game(answer) 69 | -------------------------------------------------------------------------------- /Challenges/ChallengeSolutions/challenge_3e_word_guess_refactored.py: -------------------------------------------------------------------------------- 1 | """ 2 | Word guess refactored to use list comprehensions, perform input validation, 3 | and test functions. 4 | 5 | display_word uses a list comprehension. 6 | get_guess does some validation. 7 | Tests are in challenge_3e_word_guess_tests.py 8 | """ 9 | import random 10 | 11 | 12 | def display_word(word, guessed_letters): 13 | letters = [letter if letter in guessed_letters else '_' for letter in word] 14 | return ' '.join(letters) 15 | 16 | 17 | def guess_is_correct(guess, word): 18 | return guess in word 19 | 20 | 21 | def game_won(word, guessed_letters): 22 | for letter in word: 23 | if letter not in guessed_letters: 24 | return False 25 | return True 26 | 27 | 28 | def game_lost(guesses_left): 29 | return guesses_left == 0 30 | 31 | 32 | def get_guess(): 33 | guess = input('Guess a letter: ') 34 | valid = len(guess) == 1 and guess.isalpha() 35 | return guess.lower(), valid 36 | 37 | 38 | def word_game(word): 39 | word = word.lower() 40 | guessed_letters = [] 41 | wrong_guesses_left = 6 42 | 43 | while True: 44 | # Display current state of the game 45 | print(display_word(word, guessed_letters)) 46 | print(f'Guessed letters: {" ".join(guessed_letters)}') 47 | print(f'Guesses left: {wrong_guesses_left}\n') 48 | 49 | # Get a guess from the user 50 | guess, valid = get_guess() 51 | if not valid: 52 | print('Invalid guess. Please enter a single letter') 53 | 54 | # Handle the user's guess 55 | guessed_letters.append(guess) 56 | if guess_is_correct(guess, word): 57 | print('Correct!') 58 | else: 59 | wrong_guesses_left -= 1 60 | print('Nope!') 61 | 62 | # Check to see if they won or lost 63 | if game_won(word, guessed_letters): 64 | print(f'You won :) The word was "{word}"') 65 | return 66 | elif game_lost(wrong_guesses_left): 67 | print(f'You lost :( The word was "{word}"') 68 | return 69 | 70 | 71 | # Choose a random word 72 | with open('words.txt', 'r') as file: 73 | words = file.readlines() 74 | answer = random.choice(words).strip() 75 | 76 | word_game(answer) 77 | -------------------------------------------------------------------------------- /Challenges/ChallengeSolutions/words.txt: -------------------------------------------------------------------------------- 1 | abruptly 2 | absurd 3 | abyss 4 | affix 5 | askew 6 | avenue 7 | awkward 8 | axiom 9 | azure 10 | bagpipes 11 | bandwagon 12 | banjo 13 | bayou 14 | beekeeper 15 | bikini 16 | blitz 17 | blizzard 18 | boggle 19 | bookworm 20 | boxcar 21 | boxful 22 | buckaroo 23 | buffalo 24 | buffoon 25 | buxom 26 | buzzard 27 | buzzing 28 | buzzwords 29 | caliph 30 | cobweb 31 | cockiness 32 | croquet 33 | crypt 34 | curacao 35 | cycle 36 | daiquiri 37 | dirndl 38 | disavow 39 | dizzying 40 | duplex 41 | dwarves 42 | embezzle 43 | equip 44 | espionage 45 | euouae 46 | exodus 47 | faking 48 | fishhook 49 | fixable 50 | fjord 51 | flapjack 52 | flopping 53 | fluffiness 54 | flyby 55 | foxglove 56 | frazzled 57 | frizzled 58 | fuchsia 59 | funny 60 | gabby 61 | galaxy 62 | galvanize 63 | gazebo 64 | giaour 65 | gizmo 66 | glowworm 67 | glyph 68 | gnarly 69 | gnostic 70 | gossip 71 | grogginess 72 | haiku 73 | haphazard 74 | hyphen 75 | iatrogenic 76 | icebox 77 | injury 78 | ivory 79 | ivy 80 | jackpot 81 | jaundice 82 | jawbreaker 83 | jaywalk 84 | jazziest 85 | jazzy 86 | jelly 87 | jigsaw 88 | jinx 89 | jiujitsu 90 | jockey 91 | jogging 92 | joking 93 | jovial 94 | joyful 95 | juicy 96 | jukebox 97 | jumbo 98 | kayak 99 | kazoo 100 | keyhole 101 | khaki 102 | kilobyte 103 | kiosk 104 | kitsch 105 | kiwifruit 106 | klutz 107 | knapsack 108 | larynx 109 | lengths 110 | lucky 111 | luxury 112 | lymph 113 | marquis 114 | matrix 115 | megahertz 116 | microwave 117 | mnemonic 118 | mystify 119 | naphtha 120 | nightclub 121 | nowadays 122 | numbskull 123 | nymph 124 | onyx 125 | ovary 126 | oxidize 127 | oxygen 128 | pajama 129 | peekaboo 130 | phlegm 131 | pixel 132 | pizazz 133 | pneumonia 134 | polka 135 | pshaw 136 | psyche 137 | puppy 138 | puzzling 139 | quartz 140 | queue 141 | quips 142 | quixotic 143 | quiz 144 | quizzes 145 | quorum 146 | razzmatazz 147 | rhubarb 148 | rhythm 149 | rickshaw 150 | schnapps 151 | scratch 152 | shiv 153 | snazzy 154 | sphinx 155 | spritz 156 | squawk 157 | staff 158 | strength 159 | strengths 160 | stretch 161 | stronghold 162 | stymied 163 | subway 164 | swivel 165 | syndrome 166 | thriftless 167 | thumbscrew 168 | topaz 169 | transcript 170 | transgress 171 | transplant 172 | triphthong 173 | twelfth 174 | twelfths 175 | unknown 176 | unworthy 177 | unzip 178 | uptown 179 | vaporize 180 | vixen 181 | vodka 182 | voodoo 183 | vortex 184 | voyeurism 185 | walkway 186 | waltz 187 | wave 188 | wavy 189 | waxy 190 | wellspring 191 | wheezy 192 | whiskey 193 | whizzing 194 | whomever 195 | wimpy 196 | witchcraft 197 | wizard 198 | woozy 199 | wristwatch 200 | wyvern 201 | xylophone 202 | yachtsman 203 | yippee 204 | yoked 205 | youthful 206 | yummy 207 | zephyr 208 | zigzag 209 | zigzagging 210 | zilch 211 | zipper 212 | zodiac 213 | zombie -------------------------------------------------------------------------------- /Challenges/ChallengeSolutions/challenge_3d_word_guess_with_classes.py: -------------------------------------------------------------------------------- 1 | """ 2 | Word guess refactored to use classes. 3 | 4 | Some explanation: 5 | __init__ is the default function that gets called when you instantiate 6 | a new object, e.g. game = WordGame() 7 | 8 | Classes have properties (e.g. word) that can be accessed within the 9 | class by calling self.property_name (e.g. self.word). 10 | 11 | Methods are functions that belong to an object (e.g. game_won) and are 12 | run by calling self.method_name (e.g. self.game_won() ). 13 | 14 | In this case, display_word is a method that acts like a property 15 | because it uses a property decorator (@property), so it can be accessed 16 | by calling self.display_word, not self.display_word() <- no parentheses. 17 | """ 18 | import random 19 | 20 | 21 | # Choose a random word 22 | def random_word(): 23 | with open('words.txt', 'r') as file: 24 | words = file.readlines() 25 | word = random.choice(words).strip() 26 | return word 27 | 28 | 29 | class WordGame(object): 30 | def __init__(self): 31 | self.word = random_word().lower().strip() 32 | self.guessed_letters = [] 33 | self.wrong_guesses_left = 6 34 | 35 | @property 36 | def display_word(self): 37 | displayed_word = '' 38 | for letter in self.word: 39 | if letter in self.guessed_letters: 40 | displayed_word += letter 41 | else: 42 | displayed_word += '_' 43 | displayed_word += ' ' 44 | return displayed_word 45 | 46 | def guess_is_correct(self, guess): 47 | return guess in self.word 48 | 49 | def game_won(self): 50 | for letter in self.word: 51 | if letter not in self.guessed_letters: 52 | return False 53 | return True 54 | 55 | def game_lost(self): 56 | return self.wrong_guesses_left == 0 57 | 58 | def play_game(self): 59 | while True: 60 | # Display current state of the game 61 | print(self.display_word) 62 | print(f'Guessed letters: {" ".join(self.guessed_letters)}') 63 | print(f'Guesses left: {self.wrong_guesses_left}\n') 64 | 65 | # Get a guess from the user 66 | guess = input('Guess a letter: ') 67 | print() 68 | 69 | # Handle the user's guess 70 | self.guessed_letters.append(guess) 71 | if self.guess_is_correct(guess): 72 | print('Correct!') 73 | else: 74 | self.wrong_guesses_left -= 1 75 | print('Nope!') 76 | 77 | # Check to see if they won or lost 78 | if self.game_won(): 79 | print(f'You won :) The word was "{self.word}"') 80 | return 81 | elif self.game_lost(): 82 | print(f'You lost :( The word was "{self.word}"') 83 | return 84 | 85 | 86 | game = WordGame() 87 | game.play_game() 88 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction to Python Programming Live Training 2 | 3 | This is the code for the *O'Reilly Live Training* - **Introduction to Python Programming** presented by Arianne Dee 4 | 5 | If you are looking for other Intro to Python content by Arianne: 6 | - [Intro to Python LiveLessons video (2nd edition)](https://github.com/ariannedee/intro-to-python-2ed) 7 | - [Intro to Python LiveLessons video (old)](https://github.com/ariannedee/intro-to-python-livelessons) 8 | 9 | Before the class, please follow these instructions: 10 | 1. [Install Python](#1-install-python-38-or-higher) 11 | 2. [Install PyCharm](#2-download-pycharm) 12 | 3. [Download the code](#3-download-the-course-files) 13 | 4. [Make sure that you can run Python in PyCharm](#4-make-sure-that-you-can-run-python-in-pycharm) 14 | 15 | ## Set up instructions 16 | ### 1. Install Python 3.8 or higher 17 | Go to https://www.python.org/downloads/ 18 | 19 | Click the yellow button at the top to download the latest version of Python. 20 | 21 | Follow [these instructions](https://github.com/ariannedee/python-ide?tab=readme-ov-file#1-installing-python) 22 | if you need additional help installing or running Python on your computer. 23 | 24 | ### 2. Download PyCharm 25 | Download PyCharm Unified here: https://www.jetbrains.com/pycharm/download/ 26 | 27 | Install, open, and use the default settings. 28 | 29 | ### 3. Download the course files 30 | 31 | #### If you have git installed: 32 | Clone the repository from the URL in the "< > Code" 33 | 34 | #### If you don't know git: 35 | 1. Click the green "< > Code" button at the top-right of the page 36 | 2. Click "Download ZIP" 37 | 3. Unzip it and move the **intro-to-python-main** folder to a convenient location 38 | 39 | ### 4. Make sure that you can run Python in PyCharm 40 | 1. Open PyCharm (skip any configuration/tip windows) 41 | 42 | 2. Navigate to the **intro-to-python-main** folder and click **Open** 43 | 44 | 3. You should now have PyCharm open with the folder structure in the side panel on the left 45 | 46 | 4. In the left panel, navigate to `Examples/example_1_first_code.py` and double-click to open it in the editor 47 | 48 | 5. On the open file, right-click and select **Run 'example_1_first_code'** 49 | 50 | 6. In the Run tab on the bottom, you should see 51 | `Process finished with exit code 0` 52 | 53 | 7. Otherwise, if you got an error (exit code 1 in red), follow [these instructions](https://github.com/ariannedee/python-ide/blob/main/docs/PYTHON-IDE.md/#pycharm) 54 | for setting your Python version in PyCharm. 55 | 56 | ## FAQs 57 | 58 | ### Can I use a different code editor besides PyCharm? 59 | 60 | Yes, but it is only recommended if you already know it and are comfortable navigating to different files and running commands in the command line. 61 | If it has syntax highlighting for Python, that is ideal. 62 | 63 | If you are using VS Code, please install the Python extension. 64 | 65 | ### PyCharm can't find Python 3 66 | 67 | Follow the instructions for [Python interpreter setup](https://github.com/ariannedee/python-ide/blob/main/docs/PYTHON-IDE.md/#pycharm). 68 | -------------------------------------------------------------------------------- /Challenges/challenge_3_word_guess.py: -------------------------------------------------------------------------------- 1 | words = ['account', 'addition', 'adjustment', 'advertisement', 'agreement', 2 | 'amount', 'amusement', 'animal', 'answer', 'apparatus', 'approval', 3 | 'argument', 'attack', 'attempt', 'attention', 'attraction', 4 | 'authority', 'balance', 'behavior', 'belief', 'breath', 'brother', 5 | 'building', 'business', 'butter', 'canvas', 'chance', 'change', 6 | 'comfort', 'committee', 'company', 'comparison', 'competition', 7 | 'condition', 'connection', 'control', 'copper', 'cotton', 'country', 8 | 'credit', 'current', 'damage', 'danger', 'daughter', 'decision', 9 | 'degree', 'design', 'desire', 'destruction', 'detail', 'development', 10 | 'digestion', 'direction', 'discovery', 'discussion', 'disease', 11 | 'disgust', 'distance', 'distribution', 'division', 'driving', 12 | 'education', 'effect', 'example', 'exchange', 'existence', 'expansion', 13 | 'experience', 'expert', 'family', 'father', 'feeling', 'fiction', 14 | 'flight', 'flower', 'friend', 'government', 'growth', 'harbor', 15 | 'harmony', 'hearing', 'history', 'impulse', 'increase', 'industry', 16 | 'insect', 'instrument', 'insurance', 'interest', 'invention', 17 | 'journey', 'knowledge', 'language', 'learning', 'leather', 'letter', 18 | 'liquid', 'machine', 'manager', 'market', 'measure', 'meeting', 19 | 'memory', 'middle', 'minute', 'morning', 'mother', 'motion', 20 | 'mountain', 'nation', 'number', 'observation', 'operation', 'opinion', 21 | 'organisation', 'ornament', 'payment', 'person', 'pleasure', 'poison', 22 | 'polish', 'porter', 'position', 'powder', 'process', 'produce', 23 | 'profit', 'property', 'protest', 'punishment', 'purpose', 'quality', 24 | 'question', 'reaction', 'reading', 'reason', 'record', 'regret', 25 | 'relation', 'religion', 'representative', 'request', 'respect', 26 | 'reward', 'rhythm', 'science', 'secretary', 'selection', 'servant', 27 | 'silver', 'sister', 'sneeze', 'society', 'statement', 'stitch', 28 | 'stretch', 'structure', 'substance', 'suggestion', 'summer', 'support', 29 | 'surprise', 'system', 'teaching', 'tendency', 'theory', 'thought', 30 | 'thunder', 'transport', 'trouble', 'vessel', 'weather', 'weight', 31 | 'winter', 'writing'] 32 | hard_words = ['Awkward', 'Bagpipes', 'Banjo', 'Bungler', 'Croquet', 'Crypt', 33 | 'Dwarves', 'Fervid', 'Fishhook', 'Fjord', 'Gazebo', 'Gypsy', 34 | 'Haiku', 'Haphazard', 'Hyphen', 'Ivory', 'Jazzy', 'Jiffy', 'Jinx', 35 | 'Jukebox', 'Kayak', 'Kiosk', 'Klutz', 'Memento', 'Mystify', 36 | 'Numbskull', 'Ostracize', 'Oxygen', 'Pajama', 'Phlegm', 'Pixel', 37 | 'Polka', 'Quad', 'Quip', 'Rhythmic', 'Rogue', 'Sphinx', 'Squawk', 38 | 'Swivel', 'Toady', 'Twelfth', 'Unzip', 'Waxy', 'Wildebeest', 39 | 'Yacht', 'Zealous', 'Zigzag', 'Zippy', 'Zombie'] 40 | 41 | """ 42 | Word guessing game (hangman) 43 | Choose a word for the user to guess. 44 | The user can have 6 wrong guesses before they lose the game. 45 | After each guess, display the correct guesses, the wrong guesses, 46 | and the number of wrong guesses left. 47 | If the user doesn't win, tell them the answer. 48 | """ 49 | 50 | 51 | def word_game(): 52 | pass 53 | 54 | 55 | word_game() 56 | -------------------------------------------------------------------------------- /Challenges/ChallengeSolutions/challenge_3_word_guess.py: -------------------------------------------------------------------------------- 1 | words = ['account', 'addition', 'adjustment', 'advertisement', 'agreement', 2 | 'amount', 'amusement', 'animal', 'answer', 'apparatus', 'approval', 3 | 'argument', 'attack', 'attempt', 'attention', 'attraction', 4 | 'authority', 'balance', 'behavior', 'belief', 'breath', 'brother', 5 | 'building', 'business', 'butter', 'canvas', 'chance', 'change', 6 | 'comfort', 'committee', 'company', 'comparison', 'competition', 7 | 'condition', 'connection', 'control', 'copper', 'cotton', 'country', 8 | 'credit', 'current', 'damage', 'danger', 'daughter', 'decision', 9 | 'degree', 'design', 'desire', 'destruction', 'detail', 'development', 10 | 'digestion', 'direction', 'discovery', 'discussion', 'disease', 11 | 'disgust', 'distance', 'distribution', 'division', 'driving', 12 | 'education', 'effect', 'example', 'exchange', 'existence', 'expansion', 13 | 'experience', 'expert', 'family', 'father', 'feeling', 'fiction', 14 | 'flight', 'flower', 'friend', 'government', 'growth', 'harbor', 15 | 'harmony', 'hearing', 'history', 'impulse', 'increase', 'industry', 16 | 'insect', 'instrument', 'insurance', 'interest', 'invention', 17 | 'journey', 'knowledge', 'language', 'learning', 'leather', 'letter', 18 | 'liquid', 'machine', 'manager', 'market', 'measure', 'meeting', 19 | 'memory', 'middle', 'minute', 'morning', 'mother', 'motion', 20 | 'mountain', 'nation', 'number', 'observation', 'operation', 'opinion', 21 | 'organisation', 'ornament', 'payment', 'person', 'pleasure', 'poison', 22 | 'polish', 'porter', 'position', 'powder', 'process', 'produce', 23 | 'profit', 'property', 'protest', 'punishment', 'purpose', 'quality', 24 | 'question', 'reaction', 'reading', 'reason', 'record', 'regret', 25 | 'relation', 'religion', 'representative', 'request', 'respect', 26 | 'reward', 'rhythm', 'science', 'secretary', 'selection', 'servant', 27 | 'silver', 'sister', 'sneeze', 'society', 'statement', 'stitch', 28 | 'stretch', 'structure', 'substance', 'suggestion', 'summer', 'support', 29 | 'surprise', 'system', 'teaching', 'tendency', 'theory', 'thought', 30 | 'thunder', 'transport', 'trouble', 'vessel', 'weather', 'weight', 31 | 'winter', 'writing'] 32 | hard_words = ['Awkward', 'Bagpipes', 'Banjo', 'Bungler', 'Croquet', 'Crypt', 33 | 'Dwarves', 'Fervid', 'Fishhook', 'Fjord', 'Gazebo', 'Gypsy', 34 | 'Haiku', 'Haphazard', 'Hyphen', 'Ivory', 'Jazzy', 'Jiffy', 'Jinx', 35 | 'Jukebox', 'Kayak', 'Kiosk', 'Klutz', 'Memento', 'Mystify', 36 | 'Numbskull', 'Ostracize', 'Oxygen', 'Pajama', 'Phlegm', 'Pixel', 37 | 'Polka', 'Quad', 'Quip', 'Rhythmic', 'Rogue', 'Sphinx', 'Squawk', 38 | 'Swivel', 'Toady', 'Twelfth', 'Unzip', 'Waxy', 'Wildebeest', 39 | 'Yacht', 'Zealous', 'Zigzag', 'Zippy', 'Zombie'] 40 | 41 | """ 42 | Word guessing game (hangman) 43 | Choose a word for the user to guess. 44 | The user can have 6 wrong guesses before they lose the game. 45 | After each guess, display the correct guesses, the wrong guesses, 46 | and the number of wrong guesses left. 47 | If the user doesn't win, tell them the answer. 48 | """ 49 | import random 50 | 51 | 52 | def display_word(word, guessed_letters): 53 | displayed_word = '' 54 | for letter in word: 55 | if letter in guessed_letters: 56 | displayed_word += letter 57 | else: 58 | displayed_word += '_' 59 | displayed_word += ' ' 60 | return displayed_word 61 | 62 | 63 | def guess_is_correct(guess, word): 64 | return guess in word 65 | 66 | 67 | def game_won(word, guessed_letters): 68 | for letter in word: 69 | if letter not in guessed_letters: 70 | return False 71 | return True 72 | 73 | 74 | def game_lost(guesses_left): 75 | return guesses_left == 0 76 | 77 | 78 | def word_game(word): 79 | word = word.lower() 80 | guessed_letters = [] 81 | wrong_guesses_left = 6 82 | 83 | while True: 84 | # Display current state of the game 85 | print(display_word(word, guessed_letters)) 86 | print(f'Guessed letters: {" ".join(guessed_letters)}') 87 | print(f'Guesses left: {wrong_guesses_left}\n') 88 | 89 | # Get a guess from the user 90 | guess = input('Guess a letter: ') 91 | print() 92 | 93 | # Handle the user's guess 94 | guessed_letters.append(guess) 95 | if guess_is_correct(guess, word): 96 | print('Correct!') 97 | else: 98 | wrong_guesses_left -= 1 99 | print('Nope!') 100 | 101 | # Check to see if they won or lost 102 | if game_won(word, guessed_letters): 103 | print(f'You won :) The word was "{word}"') 104 | return 105 | elif game_lost(wrong_guesses_left): 106 | print(f'You lost :( The word was "{word}"') 107 | return 108 | 109 | 110 | # Choose a random word 111 | answer = random.choice(words) 112 | word_game(answer) 113 | --------------------------------------------------------------------------------