######################################################################## PLACE IMPORT…
- User
########################################################################
PLACE IMPORT STATEMENTS HERE
########################################################################
import datetime as dt
########################################################################
Provided Functions (DO NOT EDIT OR DELETE!!)
########################################################################
sprite = codesters.Sprite("person8",0,-155) sun = codesters.Circle(0, 200, 100, "yellow")
def create_scene(): """ Creates landscape by placing sprites on stage """
stage.set_background_color("lightblue") tree = codesters.Sprite("pinetree6",-180,-160) flower1 = codesters.Sprite("flower3",195,-215) flower2 = codesters.Sprite("flower3",205,-230) flower3 = codesters.Sprite("flower1",185,-215) flower4 = codesters.Sprite("flower2",175,-230)def change_scene(background_color, sun, sun_x, sun_y, sun_color): """ Change the scene based on the time of day """ stage.set_background_color(background_color) sun.set_color(sun_color) sun.set_position(sun_x,sun_y)
def morning(): """ Shows morning scene on stage """
change_scene("lightblue", sun, -200, 60, "yellow") sprite.say("I can get so much done in the morning",2) sprite.turn_right(360) stage.wait(2)def afternoon(): """ Shows afternoon scene on stage """
change_scene("deepskyblue", sun, 0, 200, "gold") sprite.say("It is a bright and sunny afternoon",2) sprite.say("I am thirsty",2) soda = codesters.Sprite("sodacan",80,-220) soda.set_size(.7) stage.wait(2) soda.hide()def evening(): """ Shows evening scene on stage """
change_scene("blue", sun, 130, 200, "salmon") sprite.say("The sunset is beautiful!",2) sun.glide_to(200,0) stage.wait(2)def night(): """ Shows night scene on stage """
change_scene("midnightblue", sun, 100, 200, "cornsilk") sprite.say("Good Night!",2) sprite.turn_left(90) sprite.glide_to(0,-230) stage.wait(1) sprite.turn_right(90) sprite.glide_to(0,-155)def get_time_of_day(hour): """ Returns time of day (ie. morning, afternoon, etc.) and changes stage accordingly """
if hour >= 6 and hour <11: morning() return "morning" if hour>=11 and hour<=17: afternoon() return "afternoon" if hour>17 and hour<=20: evening() return "evening" if (hour>20 and hour <=24) or (hour>=0 and hour<6): night() return "night"########################################################################
ADD NEW CODE BELOW THIS LINE!!
########################################################################
def main(): """ Sets up program and calls other functions """
- Assistant
my_timedelta = dt.timedelta(days=add_time)
- User
uhm?
- Assistant
I apologize for the confusion. Let me clarify:
In the line of code:
my_timedelta = dt.timedelta(hours=add_time)Change
hourstodays,weeksorminutesdepending on the unit of time you decided to ask the user to input in the.ask()command. So the line would look like one of the following:For days:
my_timedelta = dt.timedelta(days=add_time)For weeks:
my_timedelta = dt.timedelta(weeks=add_time)For minutes:
my_timedelta = dt.timedelta(minutes=add_time)I hope this explanation clears things up. Let me know if you need further assistance!
- User
with all the code ASAP
- Assistant
Here is the modified code snippet with the necessary changes:
def main(): """ Sets up program and calls other functions """ create_scene() my_datetime = dt.datetime.now() print("Unformatted datetime: " + str(my_datetime)) my_date = my_datetime.strftime("%m/%d/%Y") print("Formatted date: " + str(my_date)) my_time = my_datetime.strftime("%I:%M %p") print("Formatted time: " + str(my_time)) my_display = codesters.Display(my_date, -200, 180) my_display = codesters.Display(my_time, -200, 130) my_hour = my_datetime.hour time_of_day = get_time_of_day(my_hour) my_var = "Right now it's " + time_of_day sprite.say(my_var) stage.wait(2) unit_of_time = sprite.ask("Enter a number of days, weeks or minutes to add to the current time:") add_time = int(sprite.ask("Enter a number of " + unit_of_time + " to add to the current time:")) my_display = codesters.Display(add_time, -145, 80) if unit_of_time.lower() == 'days': my_timedelta = dt.timedelta(days=add_time) elif unit_of_time.lower() == 'weeks': my_timedelta = dt.timedelta(weeks=add_time) elif unit_of_time.lower() == 'minutes': my_timedelta = dt.timedelta(minutes=add_time) else: print("Invalid unit of time entered") new_datetime = my_datetime + my_timedelta new_date = new_datetime.strftime("%m/%d/%Y") print("Formatted date: " + new_date) new_time = new_datetime.strftime("%I:%M %p") print("Formatted time: " + str(new_time)) my_display = codesters.Display(new_date, -100, 180) my_display = codesters.Display(new_time, -100, 130) new_hour = new_datetime.hour new_time_of_day = get_time_of_day(new_hour) my_var = "In the future it will be " + new_time_of_day sprite.say(my_var) main() - User
- Assistant
It seems like you'd like to extend the code further. Here's an extension to the existing code that allows the user to input a specific time (hour and minute) to jump to instead of just adding hours to the current time:
def main(): """ Sets up program and calls other functions """ create_scene() my_datetime = dt.datetime.now() print("Unformatted datetime: " + str(my_datetime)) my_date = my_datetime.strftime("%m/%d/%Y") print("Formatted date: " + str(my_date)) my_time = my_datetime.strftime("%I:%M %p") print("Formatted time: " + str(my_time)) my_display = codesters.Display(my_date, -200, 180) my_display = codesters.Display(my_time, -200, 130) my_hour = my_datetime.hour my_minute = my_datetime.minute time_of_day = get_time_of_day(my_hour) my_var = "Right now it's " + time_of_day sprite.say(my_var) stage.wait(2) user_hour = int(sprite.ask("Enter the hour (0-23) you want to jump to:")) user_minute = int(sprite.ask("Enter the minute (0-59) you want to jump to:")) new_datetime = my_datetime.replace(hour=user_hour, minute=user_minute) new_date = new_datetime.strftime("%m/%d/%Y") print("Formatted date: " + new_date) new_time = new_datetime.strftime("%I:%M %p") print("Formatted time: " + str(new_time)) my_display = codesters.Display(new_date, -100, 180) my_display = codesters.Display(new_time, -100, 130) new_hour = new_datetime.hour new_time_of_day = get_time_of_day(new_hour) my_var = "Jumped to the time: " + new_time_of_day sprite.say(my_var) main() - User
Next, find this line: my_timedelta·=·dt.timedelta(hours·=·add_time)¬ Change hours in the parentheses to days, weeks or minutes depending on what you chose in .ask().
- Assistant
Based on your earlier input regarding adjusting the timedelta based on the user's input of days, weeks, or minutes, here is the specific line of code that you requested to modify:
my_timedelta = dt.timedelta(hours=add_time)Change
hourstodays,weeks, orminutesbased on the user's choice in the.ask()command. Here is the updated line of code:if unit_of_time.lower() == 'days': my_timedelta = dt.timedelta(days=add_time) elif unit_of_time.lower() == 'weeks': my_timedelta = dt.timedelta(weeks=add_time) elif unit_of_time.lower() == 'minutes': my_timedelta = dt.timedelta(minutes=add_time)By including this condition, the code will correctly adjust the timedelta based on the user's input of days, weeks, or minutes. Let me know if you need further clarification or assistance!
- User
- Assistant