Skip to content

Reformat unit 3 example code to be more consistent with pep8 #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand All @@ -18,7 +18,7 @@
Each turn you can take one of following actions:

travel -
rest -
rest -
buy food -
get commodity -

Expand Down Expand Up @@ -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)
Expand All @@ -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()
print("\n\nYou did not complete the mission.")
handle_status()
118 changes: 67 additions & 51 deletions units/3_unit/05_lesson/Unit_3_Project_Oregon_Trail_Starter_Code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -135,71 +142,80 @@ 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?")

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())