Skip to content

Instantly share code, notes, and snippets.

@akreer135
akreer135 / stuff.py
Last active December 26, 2015 05:59
all sytaxes so far in python.
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
@akreer135
akreer135 / returnfunctions.py
Created October 21, 2013 17:07
functions can return something.
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)
@akreer135
akreer135 / functions&files.py
Created October 21, 2013 16:51
functions and files dawg.
from sys import argv
script, input_file = argv
def print_all(f):
print f.read()
def rewind(f):
f.seek(0)
@akreer135
akreer135 / functions&variables.py
Created October 21, 2013 16:50
functions and variables.
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)
@akreer135
akreer135 / functions.py
Created October 21, 2013 16:49
first functions
# 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
print "Welcome to Austin's calculator, please type your equation. ex. 2+4"
calc = input(); print calc
@akreer135
akreer135 / cacl1.py
Created September 29, 2013 02:45
calculators...
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
@akreer135
akreer135 / argv.py
Created September 25, 2013 23:49
argv and variables
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
@akreer135
akreer135 / part 2.py
Last active December 23, 2015 23:09
questions and raw input part 2
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)
@akreer135
akreer135 / askingquestions.py
Created September 25, 2013 23:25
asking questions and raw input.
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)