64 lines
1.5 KiB
Python
64 lines
1.5 KiB
Python
|
def cheese_and_crackers(cheese_count, boxes_of_crackers): # define a function
|
||
|
print(f"You have {cheese_count} cheeses!") # print cheese_count
|
||
|
print(f"You have {boxes_of_crackers} boxes of crackers!") # print boxex_of_crackers
|
||
|
print("Man that's enough for a party!") # print a script
|
||
|
print("Get a blanket.\n") # print a script
|
||
|
|
||
|
def my_f(arg1, arg2):
|
||
|
total = arg1 + arg2
|
||
|
print(f"arg1: {arg1}, arg2: {arg2}, total: {total}")
|
||
|
|
||
|
print("We can just give the function numbers directly:") # print a script
|
||
|
cheese_and_crackers(20, 30) # call the function
|
||
|
|
||
|
|
||
|
print("OR, we can use variables from our script:") # print a script
|
||
|
amount_of_cheese = 10 # define a value
|
||
|
amount_of_crackers = 50 # define a value
|
||
|
|
||
|
cheese_and_crackers(amount_of_cheese, amount_of_crackers) # call the function
|
||
|
|
||
|
|
||
|
print("We can even do math inside too:") # print a script
|
||
|
cheese_and_crackers(10 + 20, 5 + 6) # call the function
|
||
|
|
||
|
|
||
|
print("And we can combine the two, variables and math:") # print a script
|
||
|
cheese_and_crackers(amount_of_cheese + 100, amount_of_crackers + 1000) # call the function
|
||
|
|
||
|
my_f(1, 2)
|
||
|
my_f(2*4, 8/2)
|
||
|
my_f("2*4", "8/2")
|
||
|
my_f("not", "bad")
|
||
|
|
||
|
n_arg1 = 1
|
||
|
n_arg2 = 2
|
||
|
|
||
|
my_f(n_arg1, n_arg2)
|
||
|
|
||
|
s_arg1 = "good"
|
||
|
s_arg2 = "luck"
|
||
|
|
||
|
my_f(s_arg1, s_arg2)
|
||
|
|
||
|
t_arg1 = 8/2+3
|
||
|
t_arg2 = 8%2
|
||
|
|
||
|
my_f(t_arg1, t_arg2)
|
||
|
|
||
|
|
||
|
m_a1 = """line1
|
||
|
line2
|
||
|
line3
|
||
|
"""
|
||
|
m_a2 = """line4
|
||
|
line5
|
||
|
line6
|
||
|
"""
|
||
|
my_f(m_a1, m_a2)
|
||
|
|
||
|
my_f(open("test.txt").read(), open("test.txt").read())
|
||
|
|
||
|
f = "{} {}"
|
||
|
my_f(f.format(1, 2), f.format(3, 4))
|