Added explainer example for assignment 1
This commit is contained in:
parent
23588f682f
commit
1ae1049d5a
|
@ -0,0 +1,39 @@
|
|||
# I'm a secret magic line that will get explained at the end
|
||||
import math
|
||||
|
||||
# all assignment 1 really needs to do is
|
||||
# read inputs from the console
|
||||
# do a calculation with those inputs
|
||||
# then print out the result
|
||||
|
||||
# here is another example program that does something similar to this for ideas:
|
||||
|
||||
# this is our main function
|
||||
# it is an example of how we define a new verb
|
||||
# like when we were using things like right() and left() in our drawing with
|
||||
# the turtle
|
||||
def main():
|
||||
# every line that we want to be inside this function is going to be indented
|
||||
# indentation is how the python interpreter, the thing that actually runs the code
|
||||
# knows what to include in the function and what not to include
|
||||
|
||||
# let's use the input function to grab data from the command line
|
||||
numEggs = float(input("Enter how many eggs you eat for breakfast every day: "))
|
||||
eggsInAWeek = numEggs*7
|
||||
dozensOfEggs = math.ceil(eggsInAWeek/12) # I just looked up the easiest function to round up to the nearest whole number
|
||||
print(f"You're going to need to buy this many dozens of eggs: {dozensOfEggs}")
|
||||
|
||||
#here we're outside the definition of main() again
|
||||
#and we're able to thus *call* main
|
||||
|
||||
main()
|
||||
|
||||
# and we can run this just by calling python3 exampleAssignment1.py on the command line (the shell in replit)
|
||||
|
||||
|
||||
# oh, btw, so that import math line up above?
|
||||
# it's there so we can use these other functions that exist in Python
|
||||
# in the "standard libraries"
|
||||
# what's a library? well basically it's code that was pre-written by other people that you can use
|
||||
# Python has A Lot of pre-written code in it
|
||||
# We'll see lots of examples of including libraries as we go along with the class
|
Loading…
Reference in New Issue