Interactive Notes taken while reading:
Python Crash Course

default

########################
Python Crash Course Notes
Normal notes have been seperated.
########################

 
#! /usr/bin/env python
print()
parrot_reply = input ("I'm a parrot and can parrot back " +
    "anything you type...\nHit enter when you are done.\n\n")
print(parrot_reply)
print()
# use input() to prompt for user input.
# input() pulls in data as a string.
# In python 2.7 use raw_input() as input() expects
# python code and someone can run some unexpected code for you!

fav_color = input("What is your favorite color?: ")
print("Ooh, " +  fav_color + " is so sexy!")
print()

phone_greeting = 'Thank you for calling the Python Support Group.'
phone_greeting += '\nWhat can I help you with today? '
help_needed = input(phone_greeting)
print("\nI'd be happy to help you with " + help_needed + ".")
print()
# You can use a variable to store a prompt that is
# multiple lines long appending with +=

club_bouncer_greet = 'You must be 25 to get in, '
club_bouncer_greet += 'how old are you? '
guest_age = int(input(club_bouncer_greet))
if guest_age >= 25:
    print('Come on in. It is great to have you here!')
elif guest_age < 25:
    print('Um... You need to age a little kiddie.')
else:
    print('Hit the road! No jibberish inside here')
print()
# Data gathered with input() needs to be converted to
# integer if that is how it is intended to be used.

num = input("I know if the number you enter is odd or even: ")
num = int(num)
if num % 2 == 0:
    print('Oh yeah! I love even numbers.')
else:
    print('Neat! That is an odd number you got there')
# Modulo can determine if a number is odd or even

print('\nWhile loopin till user stops it')
buggin_ya = 'Gonna keep buggin ya, until you tell me to: stop it! '
keep_buggin = ""
while keep_buggin != 'stop it!':
    keep_buggin = input(buggin_ya)
    if keep_buggin != 'stop it!':
        print(keep_buggin)
# Keep while looping till user input terminates it.
print()

happy_wife = 'You will be well fed and nookied up! '
want_divorce = False
while not want_divorce:
    marriage = input(happy_wife)
    if marriage == "it's over!":
        want_divorce = True
        print('I got a new man!')
    elif marriage == "i'm not happy":
        want_divorce = True
        print('You are history hubby!')
    else:
        print(marriage)
        print("Unless: i'm not happy")
        print("Or: it's over!")
# Use a boolean flag to get out of marriage loop in
# several ways

print('\nTake a break out of a loop')
annoying_perv = ('what is the name of someone you slept by? ')
while True:
    lover = input(annoying_perv)
    if lover == 'nunya':
        print('Fine be that way!')
        break
    else:
        print("I'd love to meet " + lover.title() +"...")
        print("And thanks for not telling me: nunya")
# Use break to jump out of loop, abandoning remaining code
# in the loop.
# while True will make loop run until it is broken out of.

print('\nStuff a dictionary with while input')
food_orders = {}
tables_occupied = True
while tables_occupied:
    table_num = input("What table is this order for? ")
    food_order = input("What do they want to eat? ")
    food_orders[table_num] = food_order
    another_table = input('Any more tables needing to order? yes/no ')
    if another_table == 'no':
        tables_occupied = False
print('\nYo chef:')
for table_num, food_order in food_orders.items():
    print('Table ' + table_num + " wants to devour " + food_order + '.')
# Use a while loop to fill in a dictionary with food orders.

print('\nWhile up a function!')
def get_city_location(city,country):
    """Return city and country with comma inbetween"""
    city_country = city + ', ' + country
    return city_country.title()
while True:
    print("\nInput your location...")
    print("(enter 'q' at any time to quit)")
    city = input("city: ")
    if city == 'q':
        break
    country = input("\ncountry: ")
    if country == 'q':
        break
    city_location = get_city_location(city, country)
    print("\nDon't move! we will get you in " + city_location + '!')
# Create a function and then call it in a while loop

########################
Python Crash Course Notes
Normal notes have been seperated.
########################

default