From ac12344a935b15a647a85fbd5136a1e5f33850d9 Mon Sep 17 00:00:00 2001 From: Bob Fahr <20520336+bfahr@users.noreply.github.com> Date: Fri, 10 Feb 2023 16:54:38 -0600 Subject: [PATCH] Reformat example code to be more consistent with pep8 * Replace tabs with 4 spaces * Add pass to empty functions * Rename single letter function args Signed-off-by: Bob Fahr <20520336+bfahr@users.noreply.github.com> --- ...oject_Cross_Country_Canada_Starter_Code.py | 111 ++++++++-------- ...nit_3_Project_Oregon_Trail_Starter_Code.py | 118 ++++++++++-------- 2 files changed, 122 insertions(+), 107 deletions(-) diff --git a/units/3_unit/05_lesson/Unit_3_Project_Cross_Country_Canada_Starter_Code.py b/units/3_unit/05_lesson/Unit_3_Project_Cross_Country_Canada_Starter_Code.py index 84cc4f2c8..2113aaf74 100644 --- a/units/3_unit/05_lesson/Unit_3_Project_Cross_Country_Canada_Starter_Code.py +++ b/units/3_unit/05_lesson/Unit_3_Project_Cross_Country_Canada_Starter_Code.py @@ -3,9 +3,9 @@ # List assumptions of your Cross Country Canada game # Some examples: # Travel is always West. Starts in Vancouver and ends in Halifax. -# The player eats 5 kg of food every day -# The player travels between 500km to 1200km each trip, and takes 1-3 days -# ... etc. +# The player eats 5 kg of food every day +# The player travels between 500km to 1200km each trip, and takes 1-3 days +# ... etc. # welcome the user and explain the game rules welcome_text = """ @@ -18,7 +18,7 @@ Each turn you can take one of following actions: travel - - rest - + rest - buy food - get commodity - @@ -60,69 +60,68 @@ # functions # assign player a list of commodities def print_dispatch_notice(): - # randomly select commodities to deliver for this trip + # randomly select commodities to deliver for this trip + + # creat dispatch notice text and print + dispatch_notice_text = "" + print(dispatch_notice_text) + - # creat dispatch notice text and print - dispatch_notice_text = "" - print(dispatch_notice_text) - - # handle the buy food command def handle_buy_food(): - # purchase a random amount of food as defined by the game rules + # purchase a random amount of food as defined by the game rules - buy_food_text = "" - print(buy_food_text) + buy_food_text = "" + print(buy_food_text) # handle the travel command def handle_travel(): - # moves player randomly between MIN_KM_PER_TRAVEL and MAX_KM_PER_TRAVEL + # moves player randomly between MIN_KM_PER_TRAVEL and MAX_KM_PER_TRAVEL - travel_text = "" - print(travel_text) + travel_text = "" + print(travel_text) # handle the rest command def handle_rest(): - rest_text = "" - print(rest_text) + rest_text = "" + print(rest_text) # handle the get command def handle_get_commodity(): - # check if the player has arrived at a city + # check if the player has arrived at a city - # print result - get_commodity_text = "" - print(get_commodity_text) + # print result + get_commodity_text = "" + print(get_commodity_text) # handle the status command def handle_status(): - print("Here's the status:") + print("Here's the status:") - # create the report on current status + # create the report on current status # handle the help command def handle_help(): - print(help_text) + print(help_text) # handle the quit command def handle_quit(): - global playing - playing = False + global playing + playing = False # handle invalid user action def handle_invalid_input(response): - print("'{0}' is not a valid command. Try again.".format(response)) + print("'{0}' is not a valid command. Try again.".format(response)) # check if the game is over, returns a boolean def game_is_over(): - return False #update the function to check if the game is over + return False # update the function to check if the game is over # check if the player won, return a boolean def player_wins(): - return True #update the function to check if the player won - + return True # update the function to check if the player won print(welcome_text + help_text) @@ -134,31 +133,31 @@ def player_wins(): handle_status() while playing: - print() - action = input("Choose an action, {0}: ".format(player_name)) - if action == "travel" or action == "t": - handle_travel() - elif action == "rest" or action == "r": - handle_rest() - elif action == "buy food" or action == "b": - handle_buy_food() - elif action == "get commodity" or action == "g": - handle_get_commodity() - elif action == "quit" or action == "q": - handle_quit() - elif action == "help" or action == "?": - handle_help() - elif action == "status" or action == "s": - handle_status() - else: - handle_invalid_input(action) - - if game_is_over(): - playing = False + print() + action = input("Choose an action, {0}: ".format(player_name)) + if action == "travel" or action == "t": + handle_travel() + elif action == "rest" or action == "r": + handle_rest() + elif action == "buy food" or action == "b": + handle_buy_food() + elif action == "get commodity" or action == "g": + handle_get_commodity() + elif action == "quit" or action == "q": + handle_quit() + elif action == "help" or action == "?": + handle_help() + elif action == "status" or action == "s": + handle_status() + else: + handle_invalid_input(action) + + if game_is_over(): + playing = False if player_wins(): - print("\n\nCongratulations, you made it!") - handle_status() + print("\n\nCongratulations, you made it!") + handle_status() else: - print("\n\nYou did not complete the mission.") - handle_status() \ No newline at end of file + print("\n\nYou did not complete the mission.") + handle_status() diff --git a/units/3_unit/05_lesson/Unit_3_Project_Oregon_Trail_Starter_Code.py b/units/3_unit/05_lesson/Unit_3_Project_Oregon_Trail_Starter_Code.py index 6275b178d..328f70fb9 100644 --- a/units/3_unit/05_lesson/Unit_3_Project_Oregon_Trail_Starter_Code.py +++ b/units/3_unit/05_lesson/Unit_3_Project_Oregon_Trail_Starter_Code.py @@ -74,30 +74,33 @@ # Converts are numeric date into a string. -# input: m - a month in the range 1-12 -# input: d - a day in the range 1-31 +# input: the_month - a month in the range 1-12 +# input: the_day - a day in the range 1-31 # output: a string like "December 24". # Note: this function does not enforce calendar rules. It's happy to output # impossible strings like "June 95" or "February 31" -def date_as_string(m, d): - # Enter your code here - +def date_as_string(the_month, the_day): + # Enter your code here + pass def date_report(): - # Enter your code here + # Enter your code here + pass def miles_remaining(): - # Enter your code here + # Enter your code here + pass # Returns the number of days in the month (28, 30, or 31). -# input: an integer from 1 to 12. 1=January, 2=February, etc. +# input: the_month - an integer from 1 to 12. 1=January, 2=February, etc. # output: the number of days in the month. If the input is not in # the required range, returns 0. -def days_in_month(m): - # Enter your code here - +def days_in_month(the_month): + # Enter your code here + pass + # Calculates whether a sickess occurs on the current day based # on how many days remain in the month and how many sick days have # already occured this month. If there are N days left in the month, then @@ -109,13 +112,16 @@ def days_in_month(m): # 2 sick days each month, and incidentally that every day of the month # is equally likely to be a sick day (proof left to the reader!) def random_sickness_occurs(): - # Enter your code here + # Enter your code here + pass def handle_sickness(): - # Enter your code here + # Enter your code here + pass def consume_food(): - # Enter your code here + # Enter your code here + pass # Repairs problematic values in the global (month, day) model where the day is # larger than the number of days in the month. If this happens, advances to the next @@ -126,7 +132,8 @@ def consume_food(): # # Returns True if the global month/day values were altered, else False. def maybe_rollover_month(): - # Enter your code here + # Enter your code here + pass # Causes a certain number of days to elapse. The days pass one at a time, and each # day brings with it a random chance of sickness. The sickness rules are quirky: player @@ -135,40 +142,49 @@ def maybe_rollover_month(): # # input: num_days - an integer number of days that elapse. def advance_game_clock(num_days): - # Enter your code here + # Enter your code here + pass def handle_travel(): - # Enter your code here + # Enter your code here + pass def handle_rest(): -# Enter your code here + # Enter your code here + pass def handle_hunt(): - # Enter your code here + # Enter your code here + pass def handle_status(): - # Enter your code here + # Enter your code here + pass def handle_help(): -# Enter your code here + # Enter your code here + pass def handle_quit(): - global playing - playing = False + global playing + playing = False def handle_invalid_input(response): - print("'{0}' is not a valid command. Try again.".format(response)) + print("'{0}' is not a valid command. Try again.".format(response)) def game_is_over(): - # Enter your code here + # Enter your code here + pass def player_wins(): - # Enter your code here + # Enter your code here + pass def loss_report(): - # Enter your code here + # Enter your code here + pass print(welcome_text + help_text + good_luck_text) player_name = input("\nWhat is your name, player?") @@ -176,30 +192,30 @@ def loss_report(): playing = True handle_status() while playing: - print() - action = input("Choose an action, {0} -->".format(player_name)) - if action == "travel" or action == "t": - handle_travel() - elif action == "rest" or action == "r": - handle_rest() - elif action == "hunt" or action == "h": - handle_hunt() - elif action == "quit" or action == "q": - handle_quit() - elif action == "help" or action == "?": - handle_help() - elif action == "status" or action == "s": - handle_status() - else: - handle_invalid_input(action) - - if game_is_over(): - playing = False + print() + action = input("Choose an action, {0} -->".format(player_name)) + if action == "travel" or action == "t": + handle_travel() + elif action == "rest" or action == "r": + handle_rest() + elif action == "hunt" or action == "h": + handle_hunt() + elif action == "quit" or action == "q": + handle_quit() + elif action == "help" or action == "?": + handle_help() + elif action == "status" or action == "s": + handle_status() + else: + handle_invalid_input(action) + + if game_is_over(): + playing = False if player_wins(): - print("\n\nCongratulations you made it to Oregon alive!") - handle_status() + print("\n\nCongratulations you made it to Oregon alive!") + handle_status() else: - print("\n\nAlas! You lose.") - handle_status() - print(loss_report()) + print("\n\nAlas! You lose.") + handle_status() + print(loss_report())