<jupyter_start><jupyter_text>Hi! Welcome Back to Python! Here are some examples to make sure we're on the same page! All examples on this page are in Python 2.7.  Unit 1: Jumping Back In  Greetings Chatbot In this example, we'll look at *conditional statements* and getting *input* from the command line. We'll also look at some string methods like lower().<jupyter_code>reply = raw_input("How are you? ").lower()  # This is chaining. The value from raw_input is passed to the lower function
if "fine" in reply:
    reply = raw_input("Oh good! What's your name? ")
elif "not good" in reply:
    reply = raw_input("Oh bummer! What's your name? ")
else:
    reply = raw_input("Huh! What's your name? ")
print "Nice to meet you, " + reply + "!"<jupyter_output><empty_output><jupyter_text>Motivational Quote Generator Now let's look at how to *import* a module -- a bit of code that someone else wrote so that you can have extra functionality!<jupyter_code>import random
quotes = ["So it turns out that being an adult is mostly just Googling how to do stuff. (Anonymous)",
          "The best way to predict the future is to invent it. (Alan Kay)",
         "Take criticism seriously, but not personally. If there is truth or merit in the criticism, try to learn from it. Otherwise, let it roll right off you. (<NAME>)"]
print random.choice(quotes)  # choice is a function contained in the random module<jupyter_output>Take criticism seriously, but not personally. If there is truth or merit in the criticism, try to learn from it. Otherwise, let it roll right off you. (<NAME>)<jupyter_text>Coffee Bot Exercise Write a CoffeeBot that asks if you would like cream.- It should accept Yes/yes or No/no as inputs, and reply appropriately depending on the answer.- If the user inputs anything else, it should repeat back their answer and say that it does not understand.Examples:<jupyter_code># Write your CoffeeBot code here!<jupyter_output><empty_output><jupyter_text>Fortune Cookie Exercise Write a fortune cookie generator that prints out a random fortune when theprogram is run.<jupyter_code># Write your fortune cookie generator here!<jupyter_output><empty_output><jupyter_text>Unit 2: Loops Here, we'll practice *loop*ing over lists.  Nosy Question Bot<jupyter_code>import random

# Introduction
print "Hello, this is Nosy Question Bot. I'd like to ask you a few questions!"

questions = ["Given the choice of anyone in the world, whom would you want as a dinner guest?",
            "Would you like to be famous? In what way?", "What would be a perfect day for you?"]

responses = ["Interesting.", "I see!", "Fascinating."]

# Make a loop that asks the question from the list
for question in questions:
    print question
    
    # Get a reply but don't do anything with it
    raw_input()
    
    print(random.choice(responses))
    
print "You are a super interesting person! Thanks for replying to my questions."<jupyter_output><empty_output><jupyter_text>New Years Bot Exercise Write a New Years Bot that counts down from 10 to 1. - It should use a loop and each number should be on a new line.- At the end of the countdown, it should output Happy New Year!You may use a list to hold your numbers, or use math if you know it (we'll practice the latter in a bit.)Example:<jupyter_code># Write your New Years Bot here!<jupyter_output><empty_output><jupyter_text>Unit 3: Math and Loops (Cont'd) In this unit, we'll practice *addition* and counting using accumulator variables.  Vancouver Popular Cafes This program will get input from 5 people to find out what their favourite cafe is, between **Starbucks** and **Tim Hortons**. At the end, it prints out the number of people who like each.<jupyter_code># Initialize counters
starbucks_count = 0
timmys_count = 0

for i in range(5):
    
    # Ask the user what their favourite cafe is
    favourite_cafe = raw_input(
        "What's your favourite cafe out of Starbucks and Tim Hortons? ")
    
    if favourite_cafe.lower() == "starbucks":
        starbucks_count = starbucks_count + 1  # Add 1 to the count
    
    elif favourite_cafe.lower() == "tim hortons":
        timmys_count += 1  # Equivalent to the above
    
print starbucks_count
print timmys_count

# Can you print a statement here about which cafe is more popular, using the > or < operators?<jupyter_output><empty_output><jupyter_text>Chip Rater  In this example, you'll practice converting between data *types* and using *division*.<jupyter_code># Greetings
print "Welcome to Chip Rater. I'd like you to answer a few questions."

# List of questions
questions = ["How crispy is the chip out of 5? ", 
             "How would you rate the packaging out of 5? ", 
             "How would you rate the taste out of 5? "]

# Initialize score
total = 0

# Go through each question and get rating
for question in questions:
    rating = int(raw_input(question))  # Converting to integer type
    total += rating

# Calculate average rating
num_questions = len(questions)
print "You've rated this chip a " + str(total/num_questions) + "!"<jupyter_output><empty_output><jupyter_text>Olympic Judging Exercise Write an Olympic Judging program that outputs the average scores from 5 different judges. - Each score is out of 10 points maximum. - Half points are allowed (e.g. 7.5 - remember the *float* data type)The program should take 5 inputs and output the final average score. Example:<jupyter_code># Write your Olympic Judge program here!<jupyter_output><empty_output><jupyter_text>Unit 4: Functions, Indexing, and Nesting Here, we'll look at *functions*. Recall that we used the functions inside the random module earlier. We can write our own functions, in order to not have to copy/paste everywhere.  Power Function Exercise<jupyter_code># An example of a "fruitful function" that returns a value
def power(x,y):
    return x**y

# Add code below that calls the power function and prints out the result<jupyter_output><empty_output><jupyter_text>Now, try using the **power** function above by *calling* it with 2 *parameters*. Add your code in the box above, but below the function definition.  Word Finder Exercise In some of the code you will read this week, sometimes functions return more than one value! Try this one.<jupyter_code># Here we define a function
def find_word_that_starts_with(wordlist, letter):
    
    # We want to return the word and the location in the wordlist
    for i in range(len(wordlist)):
        
        # Get the word at index i
        word = wordlist[i]
        
        # Check first letter at index 0
        if word[0] == letter:
            return (wordlist[i], i)
        
    # If we went through the whole list and couldn't find anything, return None
    return (None, None)

# -------------------------

# Now let's call the function
(word, location) = find_word_that_starts_with(["peacocks", "emu", "kangaroo"], "p")

if word != None:
    print word, location
else:
    print "Not found"<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0782122905027933, 'fraction_numerical': 0.004154132645752757, 'mean_word_length': 3.9978525411596277, 'pattern_counts': {'":': 2, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '251988', 'license': 'MIT', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1931, 'n_words': 945, 'path': '1.Python_Refresher.ipynb', 'repo_name': 'AngelicaLim/ai4all', 'size': '6999'}