ungleich-learning-circle/youngjin.han/python-the-hard-way/ex24.py

43 lines
1.5 KiB
Python

print("Let's practice everything.") # print a script
print('You\'d need to know \'bout escapes with \\ that do:') # print a script
print('\n newlines and \t tabs.') # print a script
# define a string array
poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
"""
print("--------------") # print a script
print(poem) # print a script
print("--------------") # print a script
five = 10 - 2 + 3 - 6 # calculate a number
print(f"This should be five: {five}") # print a script
def secret_formula(started): # define a function
jelly_beans = started * 500 # calculate a number
jars = jelly_beans / 1000 # calculate a number
crates = jars / 100 # calculate a number
return jelly_beans, jars, crates # return values
start_point = 10000 # define a value
beans, jars, crates = secret_formula(start_point) # run a function
# remember that this is another way to format a string
print("With a starting point of: {}".format(start_point)) # print a script
# it's just like with an f"" string
print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.") # print a script
start_point = start_point / 10 # calculate a number
print("We can also do that this way:") # print a script
formula = secret_formula(start_point) # run a function
# this is an easy way to apply a list to a format string
print("We'd have {} beans, {} jars, and {} crates.".format(*formula)) # print a script