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
# Recursion practice | |
# Recurion loop version of a while loop[] | |
triangle = ["one"] | |
def pyramid(): | |
print(triangle) | |
triangle.append("one") | |
line_len = len(triangle) |
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
# triangle.py | |
# Recurion loop practice starting with a while loop example | |
triangle = ["one"] | |
def pyramid(): | |
while len(triangle) < 6: | |
line_len = len(triangle) | |
print(triangle) | |
triangle.append("one") |
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
# Class excercise | |
# Return statements practice | |
def helloworld(): | |
print("hello world") | |
helloworld() | |
def isodd(num): |
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
import graphicsPlus as gr | |
win = gr.GraphWin("Simple Circle", 400, 400) | |
def text(): | |
textblock = gr.Text(gr.Point(100, 100), "Hello!") | |
textblock.setSize(18) | |
textblock.draw(win) | |
def main(): | |
text() |
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
# prints a string letter-by-letter | |
def num_letter_test(x): | |
string_input = x | |
string_len = len(string_input) | |
counter = 0 | |
for i in range(string_len): | |
print(string_input[counter]) | |
counter += 1 |
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
# Simple value returning function, with nested conditional and boolean check/return | |
# return_test7.py | |
def pass_info(x, y): | |
add = x + y | |
# added a nested condition, checking if odd or even and assigning a boolean | |
if (add % 2 == 0): | |
boo = True | |
elif (add % 2 == 1): | |
boo = False |
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
# Simple value returning function, with nested conditional and boolean check/return | |
# return_test5.py | |
def pass_info(x, y): | |
add = x + y | |
# adding a nested condition and operation doesn't seem to impact return statement | |
if add < 10: | |
boo = False | |
return boo |
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
# Simple value returning function, two retunred values | |
# return_test4.py | |
def pass_info(x, y): | |
add = x + y | |
# adding a nested condition and operation doesn't seem to impact return statement | |
if add < 10: | |
add = 11 | |
return add |
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
# Simple value returning function, two retunred values | |
# return_test3.py | |
def pass_info(x, y): | |
add = x + y | |
sub = x - y | |
# note, if one return variable is removed then the main function will only output remaining value | |
return add, sub | |
def main(): |
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
# Simple value returning function, plus odd or even test | |
# return_test2.py | |
def pass_info(x, y): | |
sum = x + y | |
# nested conditional testing if a new math operation changes the sum returned? | |
# tests if sum is even | |
if (sum % 2 == 0): | |
sum += 1 | |
# tests if sum is odd |
NewerOlder