#rite a function called get_todays_date that returns#today’s date as a
#rite a function called get_todays_date that returns#today’s date as a
string, in the form year/month/day.
#For example, if today is January 15th, 2017, then it
#would return 2017/1/15.
#
#Remember, you took care of the string formatting part of
#this exercise in 2.2.9 Coding Exercise 1! Now, you’re
#converting it to a function that returns the string.
#
#Note that the line below will let you access today’s date
#using date.today() anywhere in your code.
from datetime import date
mydate = date.today()
mydate.year = date.today.year()
mydate.month = date.today.month()
mydate.day = date.today.day()
def get_todays_date():
return date.year() + “/” + date.month() + “/” +str(date.day)
print(get_todays_date ())
Problem 2
rite a function called get_todays_date that returns
#today’s date as a string, in the form year/month/day.
#For example, if today is January 15th, 2017, then it
#would return 2017/1/15.
#
#Remember, you took care of the string formatting part of
#this exercise in 2.2.9 Coding Exercise 1! Now, you’re
#converting it to a function that returns the string.
#
#Note that the line below will let you access today’s date
#using date.today() anywhere in your code.
from datetime import date
mydate = date.today()
mydate.year = date.today.year()
mydate.month = date.today.month()
mydate.day = date.today.day()
def get_todays_date():
return date.year() + “/” + date.month() + “/” +str(date.day)
print(get_todays_date ())
Problem 3
#Below we’ve written a function that is supposed to take in
#four parameters and produce a string representing the cost
#of a person’s weekly soda consumption. Below the function
#definition, we’re calling the function.
#
#However, right now, the code is erroring out. Fix this code
#without changing the code inside the function. You may
#change either the function declaration (on line 11) or the
#function call on line 27.
def soda_habit(preferred_soda,calories_per_soda,price_per_soda,sodas_per_week):
money_spent = price_per_soda*sodas_per_week
calories_consumed = calories_per_soda*sodas_per_week
summary_string = “You’re spending $”+ str(money_spent)+” on “+preferred_soda+” per week! “
summary_string+= ” That’s “+ str(calories_consumed)+ ” calories! “
return summary_string
”’The order of the function parameters declared above
And the order of values with which the function is called
should be the same so that they match with each other
”’
result = soda_habit(“Coca-Cola”,140,1.75,9)