<jupyter_start><jupyter_text>Getting Started with Python Hello, WorldIt’s traditional when learning a new language to write a program that says hello to the world. It’s a very simple program, that simply produces the output `Hello, world!`.<jupyter_code>print('Hello, world!')<jupyter_output>Hello, world!<jupyter_text>Getting InputIt’s good to be able to get text input from the user (the person running the program). Here’s an example:<jupyter_code>food = input('What is your favorite food? ')<jupyter_output>What is your favorite food? muffins<jupyter_text>If you are expecting integers (whole numbers), use the `int` function like this:<jupyter_code>num_shields = int(input('How many shields do you want to buy? '))<jupyter_output>How many shields do you want to buy? 6<jupyter_text>Doing Different Things Depending on Input ReceivedMaybe the program has a special message for people whose favorite food is muffins, and another message for others:<jupyter_code>if food == 'muffins':
    print('Yes, muffins are great!')
else:
    print('I love muffins.')<jupyter_output>Yes, muffins are great!<jupyter_text>Here’s a shorter way to write that code:<jupyter_code>print('Yes, muffins are great!' if food == 'muffins' else 'I love muffins.')
if num_shields > 5:
    print('Sorry, you can buy only up to five shields at a time.')<jupyter_output>Sorry, you can buy only up to five shields at a time.<jupyter_text>Using a Dictionary to Retrieve a Different Message for Each Known Person<jupyter_code>messages = {
    'sam':   'Hey, little brother!',
    'fred':  'Congrats on the new lawn-mowing job.',
    'betty': "Where's that five dollars you owe me?",
}

name = input('What is your name? ')
nameLower = name.lower()

if nameLower in messages:
    print(messages[nameLower])
else:
    print("I don't know any " + name)<jupyter_output>What is your name? sam
Hey, little brother!<jupyter_text>Using a Tuple and `in` to Identify “Happy” Words<jupyter_code>cond = input('How are you feeling? ')
happy_words = ('fine', 'good', 'great', 'super')
if cond.lower() in happy_words:
    print("That's great!")<jupyter_output>How are you feeling? Super
That's great!<jupyter_text>SimulationsIt can be fun to simulate things, like flipping a coin many times.<jupyter_code>from random import randint

numHeads = 0
numTails = 0

for t in range(100):
    if randint(1, 2) == 1:
        numHeads += 1
    else:
        numTails += 1
        
print('There were %s heads and %s tails' % (numHeads, numTails))<jupyter_output>There were 48 heads and 52 tails<jupyter_text>Guessing GamesIn this program, the player guesses the number the computer chooses randomly.<jupyter_code>from random import randint
print('''
Welcome to the high-low guessing game.
I am thinking of an integer between 1 and 100.
''')

guess = 0
guesses = 0
number = randint(1, 100)

while guess != number:
    guesses += 1
    guess = int(input('What is your guess? '))

    if guess > number:
        print('Too high')
    elif guess < number:
        print('Too low')

print('You found the number in', guesses, 'guesses')<jupyter_output>Welcome to the high-low guessing game.
I am thinking of an integer between 1 and 100.

What is your guess? 50
Too low
What is your guess? 75
Too high
What is your guess? 62
Too high
What is your guess? 56
Too high
What is your guess? 53
Too low
What is your guess? 54
You found the number in 6 guesses<jupyter_text>Math GamesHere, the program gives math problems, for quick mental math practice.<jupyter_code>from random import randint
from time import time

print('Enjoy a math quiz, and respond with nothing to stop.')

while True:
    m1 = randint(2, 11)
    m2 = randint(2, 11)
    product = m1 * m2
    start_time = time()
    response = input('What is %d * %d ' % (m1, m2))
    if not response.strip():
        break
    answer = int(response)

    if answer == product:
        print('Right, in %.2f seconds' % (time() - start_time))
    else:
        print('Wrong, the answer was %d' % product)<jupyter_output>Enjoy a math quiz, and respond with nothing to stop.
What is 10 * 11 110
Right, in 3.20 seconds
What is 11 * 8 89
Wrong, the answer was 88
What is 11 * 5 55
Right, in 2.20 seconds
What is 6 * 3<jupyter_text>A Music QuizThis program asks questions about music.<jupyter_code>from random import shuffle
print('Welcome to the wonderful quiz on music!')

qas = [
    ('How many beats are there per measure in 2/4 time?', '2'),
    ('In what family of instruments is the piano?', 'percussion'),
    ('How many strings does a violin have?', '4')
]
shuffle(qas)
numRight = 0
wrong = []

numQuestions = int(input("How many questions? "))

for question, rightAnswer in qas[:numQuestions]:
    answer = input(question + ' ')
    if answer.lower() == rightAnswer:
        print('Right!')
        numRight += 1
    else:
        print('No, the answer is %s.' % rightAnswer)
        wrong.append(question)

print('You got %d right and the following wrong:' % (numRight))
for q in wrong:
    print(q)<jupyter_output>Welcome to the wonderful quiz on music!
How many questions? 2
In what family of instruments is the piano? percussion
Right!
How many beats are there per measure in 2/4 time? 3
No, the answer is 2.
You got 1 right and the following wrong:
How many beats are there per measure in 2/4 time?<jupyter_text>Text Adventure GamesHere is a very simple starting point for an adventure game:<jupyter_code>from random import choice, randint

transitions = {
    'airstrip': ('forest',),
    'forest':   ('airstrip', 'cave'),
    'cave':     ('forest', 'meadow'),
    'meadow':   ('cave',),
}
places = tuple(transitions.keys())
place = choice(places)
alive = True

while alive:
    print('You are at the', place)
    destinations = transitions[place]
    print('From here you can go to', ', '.join(destinations))
    new_place = input('Where would you like to go? ')
    if new_place == 'quit':
        break
    else:
        if new_place in destinations:
            if randint(1, 10) == 1:
                print('You were struck by lightning. Game over.')
                alive = False
            else:
                place = new_place
                if place == 'meadow':
                    if randint(1, 3) == 1:
                        print('You fell in a hole and you are stuck.')
                        alive = False
                    elif randint(1, 3) == 1:
                        print('You discover an amazing treasure!')
        else:
            print("You can't go there.")<jupyter_output>You are at the meadow
From here you can go to cave
Where would you like to go? cave
You are at the cave
From here you can go to forest, meadow
Where would you like to go? park
You can't go there.
You are at the cave
From here you can go to forest, meadow
Where would you like to go? meadow
You discover an amazing treasure!
You are at the meadow
From here you can go to cave
Where would you like to go? quit
{'fraction_non_alphanumeric': 0.09788895315211105, 'fraction_numerical': 0.015615962984384037, 'mean_word_length': 3.4915584415584417, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 39, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '564392', 'license': 'MIT', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2103, 'n_words': 888, 'path': 'doc/Getting Started.ipynb', 'repo_name': 'beshad/python-lessons', 'size': '6916'}