Skip to content

Instantly share code, notes, and snippets.

@AnisahTiaraPratiwi
Created March 20, 2021 10:17
Show Gist options
  • Save AnisahTiaraPratiwi/f79debd0d84da325dd2473e0c3de3b6f to your computer and use it in GitHub Desktop.
Save AnisahTiaraPratiwi/f79debd0d84da325dd2473e0c3de3b6f to your computer and use it in GitHub Desktop.
In this code, identify the repeated pattern and replace it with a function called month_days, that receives the name of the month and the number of days in that month as parameters. Adapt the rest of the code so that the result is the same. Confirm your results by making a function call with the correct parameters for both months listed.
# REPLACE THIS STARTER CODE WITH YOUR FUNCTION
def month_days(month,days):
print(month + " has " + str(days) + " days.")
month_days("June","30")
month_days("July","31")
@NDEDE
Copy link

NDEDE commented Apr 19, 2022

Excellent!

@mdshagor369
Copy link

Nice. It will help me.

@s1032945
Copy link

this code didn't work

@minhtetoo31
Copy link

`This answer is for this question type.

def month_days(month, days):
result = f"{month} has {days} days."
return (result)
print (month_days("June", 30))
print (month_days("July", 31))`

@minhtetoo31
Copy link

this code didn't work

This answer is for this question type.

def month_days(month, days):
result = f"{month} has {days} days."
return (result)
print (month_days("June", 30))
print (month_days("July", 31))

@MoDev-all
Copy link

This is the correct answer:

def month_days(month,days):
m_days = days
print(month + " has " + str(m_days) + " days.")

month_days("june", 30)
month_days("july", 31)

@rubycarefree
Copy link

Python

def month_days(month, days):
print(month, "has", days, "days.")
month_days("June","30")
month_days("July","31")

@rubycarefree
Copy link

this code didn't work
To get it right, you should replace "+" with "," in the print line.

@0022peter
Copy link

I don't get it

@0022peter
Copy link

Arent we suppose to remove the instruction in line 1 a and replace it

@Shahzad-15
Copy link

Shahzad-15 commented Sep 10, 2022

def month_days(month,days):
print (month +" has "+ str(days) +" days.")
month_days("June",30)
month_days("July",31)
#TRICK is to add spaces, it is actually " has " not "has", so add spaces before and after writing "has" inside the apostrophes and also before "days." and it will work.
for more clarity:
correct one= " has " " days."
wrong one = "has" "days."
I hope it made sense :)

@DerikVo
Copy link

DerikVo commented Oct 22, 2022

So I was wondering why my code wasn't accepted. Turns out you have to use their exact variable name. I was using "month_day", but the program was expecting "month_days" so it was not accepted.
Learned I need to carefully read the requirements and follow them. Hope that helps others who are wondering.

@abuzar01440
Copy link

def month_days(months, days):
x=(f"{months} has {days} days")
return x
print(month_days("June", 30))
print(month_days("July", 31))

output:

June has 30 days
July has 31 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment