[Tutor] Principles of code reuse error (Nagaraj S)

Dennis Lee Bieber wlfraed at ix.netcom.com
Sat Nov 20 12:45:34 EST 2021


On Sat, 20 Nov 2021 03:21:54 +0530, Nagaraj S <archinagaraj at gmail.com>
declaimed the following:

>
>Below is the question, answer and the result error I received.
>
>
>In this code, identify the repeated pattern and replace it with a function

	You have failed to show US "this code". We have no idea what the
"repeated pattern" might be.

>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.
>
>def month_days(month, days):
>   print(month +" has " + days +" days")

	It's been mentioned that you may need to return the result rather than
directly print it...

>month_days("june", "30")
>month_days("july", "31")
>
	You are passing the NUMBER of days as STRINGs, not numbers.

>Here is your output:
>june has 30 days
>july has 31 days
>
>Not quite. Let your function do most of the work and just
>pass the name of the month and the associated days as
>parameters.


	Again, seeing the "original" code may be required. Technically, you are
passing the month name, and (as string) the days in the month. Though
personally, I'd consider this function to be error-prone -- consider: 
	month_days("February", "32").
The function requires the caller to KNOW the days in the month, and is just
formatting them for output.

	I'd have expected some example where one provides the name of the
month, and the function /returns/ the days in that month.
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/



More information about the Tutor mailing list