Skip to content

Instantly share code, notes, and snippets.

View chicagowebmanagement's full-sized avatar

Patrick Elward chicagowebmanagement

View GitHub Profile
"""
Write a function that takes
a number as an input
and returns that number squared.
"""
def getSquared(x):
x=x*x
return x
"""
takes a value and passes BACK into the function
"""
def razors(sharpness)
return print(sharpness)
razors("Go! Go! Go!)
@chicagowebmanagement
chicagowebmanagement / function-test-3.py
Created March 17, 2019 20:32
testing required and optional parameters.
"""
Write a function that takes three required parameters and two optional parameters.
"""
def tales(x, y, z, a=2, b=3):
total = (x+y+z+a+b)
print(total)
tales(4,6,0)
tales(2,5,12,67)
tales(35,67,87,-10,-3)
@chicagowebmanagement
chicagowebmanagement / function-test-4.py
Last active March 18, 2019 14:56
passing result to another function
"""
Write a program with two functions.
The first function should take an integer as a parameter and return
the result of the integer divided by 2. The second function should
take an integer as a parameter and return the result of the integer
multiplied by 4. Call the first function, save the result as a
variable, and pass it as a parameter to the second function.
"
@chicagowebmanagement
chicagowebmanagement / string-float.py
Last active March 19, 2019 03:17
testing Try and Exception converts string to float
"""
testing Try and Exception converts string to float
"""
def wakawaka(x):
"""Float a string.
Keyword arguments:
floatable value: gets printed out as result
NON-floatable value: Error message will print out
@chicagowebmanagement
chicagowebmanagement / winning2.py
Created March 19, 2019 04:25
working through functions and comments
def winning2(x,y):
""" collects input on two different numbers
input: integer
output:
Give me the first number: {some integer}
Give me another number: {some integer}
X times Y equals: {their product}
"""
"""
Author: Patrick Elward
Date: 03/19/2019
An Example of try and except
and a FIX for ZeroDivisionError if caught
"""
@chicagowebmanagement
chicagowebmanagement / lists-musicians0319.py
Last active March 20, 2019 02:04
Very simple list of five musicians with replace and append
"""
Author: Patrick Elward
Date: 03/19/2019
An Example of lists
a. Create a list of your five favorite musicians and print it.
b. Change the musician at index 4 to "John Lennon" and print your list.
c. Append a new musician to your list and print it.
"""
@chicagowebmanagement
chicagowebmanagement / lists-goofy.py
Created March 20, 2019 20:24
Another list and covering 'type' as well
x = ["donnere","valvore","kosciusko","manadara"]
print(x)
print(x[2])
print(type(x))
x = list(("gasadsf","True",99505,False))
print(x)
print(x[2])
print(type(x))
@chicagowebmanagement
chicagowebmanagement / tuple03202019.py
Created March 20, 2019 21:50
tuple exercise with Exception Handling
writer=("toni morrison", "Hunter S Thompson", "C.S. Lewis", "Richard Marcinko", "Keith Code")
print("My 5 favorite writers are: ", writer)
print(type(writer))
try:
writer[4]="Anne Proulx"
print("Revised list of writers: ", writer)
except TypeError:
print("You can't change a Tuple! Its immutable!")