This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "How old are you?", | |
age = raw_input () | |
print "How tall are you?", | |
height = raw_input () | |
print "How much do you weight?", | |
weight = raw_input () | |
print "So you're %r old, %r tall and %r heavy." % ( | |
age, height, weight) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
script, first, second, third = argv | |
print "The script is called:", script | |
print "Your first variable is:", first | |
print "Your second variable is:", second | |
print "Your third variable is:", third | |
name = raw_input("name? ") | |
snark = " good one %s" % "huh" | |
print name + snark |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add(a, b): | |
print "ADDING %d + %d" % (a, b) | |
return a + b | |
def subtract(a, b): | |
print "SUBTRACTING %d - %d" % (a,b) | |
return a - b | |
def multiply(a, b): | |
print "MULTIPLYING %d * %d" % (a, b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add(a, b): | |
print "ADDING %d + %d" % (a, b) | |
return a + b | |
def subtract(a, b): | |
print "SUBTRACTING %d - %d" % (a,b) | |
return a - b | |
def multiply(a, b): | |
print "MULTIPLYING %d * %d" % (a, b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "Let's practice everything." | |
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.' | |
poem = """ | |
\tThe lovely world | |
with logic so firmly planted | |
cannot discern \n the needs of love | |
nor comprehend passion from intuition | |
and requires an explanation | |
\n\t\twhere there is none. | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def break_words(stuff): | |
"""This function will break up words for us.""" | |
words = stuff.split(' ') | |
return words | |
def sort_words(words): | |
"""Sorts the words.""" | |
return sorted(words) | |
def print_first_word(words): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def break_words(stuff): | |
"""This function will break up words for us.""" | |
words = stuff.split(' ') | |
return words | |
def sort_words(words): | |
"""Sorts the words.""" | |
return sorted(words) | |
def print_first_word(words): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
people = 10 | |
cats = 0 | |
dogs = 5 | |
if people < cats: | |
print "Too many cats! The world is doomed!" | |
if people > cats: | |
print "Not many cats! The world is saved!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
people = 30 | |
cars = 40 | |
buses = 15 | |
if cars > people: | |
print "We should take the cars." | |
elif cars < people: | |
print "We should not take the cars." | |
else: | |
print "We can't decide." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hairs = ['brown', 'blond', 'red'] | |
eyes = ['brown', 'blue', 'green'] | |
weights = [1, 2, 3, 4] | |
the_count = [1, 2, 3, 4, 5] | |
fruits = ['apples', 'oranges', 'pears', 'apricots'] | |
change = [1, 'pennies', 2, 'dimes', 3, 'quarters'] | |
#this first kind of for-loop goes through a list | |
for number in the_count: | |
print "This is count %d" % number |