Python 板


LINE

各位先进们好, 小废物我目前在Coursera上面自学Python, 有个「应该」对各位蛮简单的练习题(非考试题目)想发问。 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 june_days = 30 print("June has " + str(june_days) + " days.") july_days = 31 print("July has " + str(july_days) + " days.") 我的问题: 1.上堂课是教要利用def month_days(这边我不知道怎麽打) 这个题目不像是在计算, 都是名词定义... 2.在Python中存在一种函数可以自动call一个月有几天吗Q_Q? 一个人搞2小时想破头也弄不出来 --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.193.212.239 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1623519787.A.D29.html
1F:→ ck574b027: 先确认你有理解题目吧,翻译那段英文看看 06/13 01:52
2F:→ eric10252013: 题目是要能够reuse the code 06/13 03:20
3F:→ alvinlin: 其实题目写得很清楚了。我帮你翻译一下好了。首先你要定 06/13 03:36
4F:→ alvinlin: 义一个函式,名字就叫 months_days。然後现在已经有一段 06/13 03:36
5F:→ alvinlin: 程式,长得像你上面的那个样子。然後因为函式是用来解决 06/13 03:36
6F:→ alvinlin: 重复性的问题。所以你要从现在已经有的那段程式-即六月 06/13 03:36
7F:→ alvinlin: 和七月-的这个范例里面找出来他们彼此之间有什麽重复的 06/13 03:36
8F:→ alvinlin: 型态。然後根据题目的要求,给予函式两个参数。分别是月 06/13 03:36
9F:→ alvinlin: 份以及该月份的日期总数。最後这个函式的输出结果必须跟 06/13 03:36
10F:→ alvinlin: 原本的程式结果相同。他的意思就是要输出一样的结果 06/13 03:36
11F:→ alvinlin: 最後你必须在你的程式就是主程式的部分,呼叫这个函式然 06/13 03:39
12F:→ alvinlin: 後给予相同的月份就是六月和七月,最後确认这个结果跟上 06/13 03:39
13F:→ alvinlin: 面这段程式输出的结果一模一样 06/13 03:39
14F:→ alvinlin: 再稍微白话一点就是你先把原本的程式执行一次然後看看输 06/13 03:42
15F:→ alvinlin: 出的结果是什麽。然後把这份程式改成用函式的方法来执行 06/13 03:42
16F:→ alvinlin: 但是结果的输出必须是相同的 06/13 03:42
17F:→ alvinlin: 我感觉这题不是在考程式撰写他是在考你的英文理解能力。 06/13 03:45
18F:→ alvinlin: 你看我中文写了这麽多他的英文才写两三句 06/13 03:45
19F:→ eric10252013: 回楼上 我完全理解英文 但我不知道怎麽写 06/13 12:12
20F:→ eric10252013: 我有作答过写出一样的结果 我晚点把我写到的答案po 06/13 12:13
21F:→ eric10252013: 出来 06/13 12:13
22F:→ panex0845: 2. https://glot.io/snippets/fzi79egpzz 06/13 14:13
23F:→ alvinlin: https://i.imgur.com/2OICyX7.jpg 06/13 14:23
24F:→ alvinlin: 好吧。帮你写好了。 06/13 14:24
25F:→ tzouandy2818: 你完全理解题意的话怎麽会解不出来 这根本不用解啊 06/13 18:57
26F:→ eric10252013: 我卡住的点就是month_days(内文),因为前面的教学影 06/15 20:53
27F:→ eric10252013: 片都只有挂号内数字,现在才知道也可以填文字,以及 06/15 20:53
28F:→ eric10252013: 原来print(这边还可以填function) 06/15 20:53
29F:→ eric10252013: 感谢楼上大神们回覆! 06/15 20:53
30F:→ JamesChen: 不知道可不可以填 第一个该做的就是试试看 06/22 07:56







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Gossiping站内搜寻

TOP