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
What I learned in python... | |
P.S. dont run this file, its not an actual file. | |
--------------------------------------------------------------------------------------- | |
1. print - prints or types out a statement. | |
2. # - allows you to write comments that do not interfear with the script | |
3. Math symbols: | |
+ adds numbers | |
- subtracts numbers | |
* multiplies numbers | |
/ divides numbers |
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
from sys import argv | |
script, input_file = argv | |
def print_all(f): | |
print f.read() | |
def rewind(f): | |
f.seek(0) |
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 cheese_and_crackers(cheese_count, boxes_of_crackers): | |
print "You have %d cheeses!" % cheese_count | |
print "You have %d boxes of crackers!" % boxes_of_crackers | |
print "Man that's enough for a party!" | |
print "Get a blanket.\n" | |
print "We can just give the function numbers directly:" | |
cheese_and_crackers(20, 30) |
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
# this one is like your scripts with argv | |
def print_two(*args): | |
arg1, arg2 = args | |
print "arg1: %r, arg2: %r" % (arg1, arg2) | |
# ok, that *args is actually pointless, we can just do this | |
def print_two_again(arg1, arg2): | |
print "arg1: %r, arg2: %r" % (arg1, arg2) | |
# this just takes one argument |
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 "Welcome to Austin's calculator, please type your equation. ex. 2+4" | |
calc = input(); print calc |
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 "Hello welcome to Austin's calculator. Would you like to use (b)asic functions or more (c)omplex functions?" | |
dec = (raw_input()) | |
if dec == "b": | |
print """(m)ultiply, (d)ivide, (a)dd, or (s)ubtract?. Don't forget, | |
this can only be integers or whole numbers.""" | |
answer = (raw_input()) | |
if answer == "m": #Multiplication |
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 |
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
age = raw_input("How old are you? ") | |
height = raw_input("How tall are you? ") | |
weight = raw_input("How much do you weigh? ") | |
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
print "How old are you?", | |
age = raw_input() | |
print "How tall are you?", | |
height = raw_input() | |
print "How much do you weigh?", | |
weight = raw_input() | |
print "So, you're %r old, %r tall and %r heavy." % ( | |
age, height, weight) |