This file contains 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
""" | |
Write a function that takes | |
a number as an input | |
and returns that number squared. | |
""" | |
def getSquared(x): | |
x=x*x | |
return x |
This file contains 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
""" | |
takes a value and passes BACK into the function | |
""" | |
def razors(sharpness) | |
return print(sharpness) | |
razors("Go! Go! Go!) |
This file contains 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
""" | |
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) |
This file contains 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
""" | |
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. | |
" |
This file contains 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
""" | |
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 |
This file contains 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 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} | |
""" |
This file contains 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
""" | |
Author: Patrick Elward | |
Date: 03/19/2019 | |
An Example of try and except | |
and a FIX for ZeroDivisionError if caught | |
""" |
This file contains 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
""" | |
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. | |
""" |
This file contains 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
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)) |
This file contains 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
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!") |
OlderNewer