Python:每日一题 76(答题领鱼币)
今天的题目比较简单,也比较综合
There are five workers : James,John,Robert,Michael and William.They work one by one and on weekends they rest. Order is same as in the description(James works on mondays,John works on tuesdays and so on).You have to create a function 'task' that will take 3 arguments(w, n, c):
1) Weekday
2) Number of trees that must be sprayed on that day
3) Cost of 1 litre liquid that is needed to spray tree,let's say one tree needs 1 litre liquid.
Let cost of all liquid be x
Your function should return string like this : 'It is (weekday) today, (name), you have to work, you must spray (number) trees and you need (x) dollars to buy liquid'
For example:
task('Monday',15,2) -> 'It is Monday today, James, you have to work, you must spray 15 trees and you need 30 dollars to buy liquid'
中文版:
有五个工作人员:James,John,Robert,Michael and William。他们一个接一个地工作,周末休息。 订单与描述中相同(James在Monday工作,John在Tuesdays等等)。您必须创建一个函数“task”,它将使用3个参数(w,n,c):
1)平日(除周末)
2)当天必须喷洒的树木数量
3)喷洒树需要1升液体的成本,假设一棵树需要1升液体。
让所有液体的成本为x
你的函数应该返回这样的字符串:
'It is (weekday) today, (name), you have to work, you must spray (number) trees and you need (x) dollars to buy liquid'
例如:
task('星期一,15,2) - >'It is Monday today, James, you have to work, you must spray 15 trees and you need 30 dollars to buy liquid'
答案:
**** Hidden Message ***** 本帖最后由 shinemic 于 2017-8-11 10:46 编辑
def task(w, n, c):
task_schedule = {'Monday': 'James', 'Tuesday': 'John',
'Wednesday': 'Robert', 'Thursday': 'Michael',
'Friday': 'William'}
return('It s %s today, %s, you have to work, '
'you must spary %.0f trees and you need %.0f '
'dolloars to buy liquid.' %
(w, task_schedule, n, n * c)) def task(w,n,c):
Dicts={'Monday':'James','Tuesday':'John','Wednesday':'Robert','Thursday':'Michael','Friday':'Willams'}
print("It is %s today, %s, you have to work, you must spray %d trees and you need %d dollars to buy liquid",%(w,Dicts,n,(n*c))) employee = {'Monday': 'James', 'Tuesday': 'John', 'Wednesday': 'Robert', 'Thursday': 'Michael', 'Friday': 'William'}
def task(w, n, c):
print("It is %s today, %s, you have to work, you must spray %d trees and you need %d dollars yo buy loquid" % (w, employee, n, n*c))
本帖最后由 ktjack2009 于 2017-8-11 15:24 编辑
def task(w,n,c):
task_dict = {'Monday':'James','Tuesdays':'John','Wednesday':'Robert','Thursday':'Michael','Friday':'William'}
print('It is %s today, %s, you have to work,you must spray %d trees and you need %d dollars to buy liquid' % (w,task_dict,n,n*c)) def task(w,n,c):
mydata=['Monday','Tuesday','Wednesday','Thursday','Friday','James','John','Robert','Michael','William']
i=mydata.index(w)
return 'It is '+str(mydata)+' today, '+str(mydata)+', you have to work, you must spray '+str(n)+' trees and you need '+str(n*c)+' dollars to buy liquid' def task(w,n,c):
mydata=['Monday','Tuesday','Wednesday','Thursday','Friday','James','John','Robert','Michael','William']
i=mydata.index(w)
return 'It is '+str(mydata)+' today, '+str(mydata)+', you have to work, you must spray '+str(n)+' trees and you need '+str(n*c)+' dollars to buy liquid' 我只是试了一下怎么能把代码粘的像代码的样子{:10_249:},新手上路 古堡主人。 发表于 2017-8-11 17:44
我只是试了一下怎么能把代码粘的像代码的样子,新手上路
{:10_295:}那也不要抄袭 新手·ing 发表于 2017-8-11 17:55
那也不要抄袭
没有抄袭,只是发了两次,两次都是我发的,不过你们竟然能这么快恢复也是让我眼前一亮,不和你聊了,我去学python了,学好之后才能爬草榴 古堡主人。 发表于 2017-8-11 21:18
没有抄袭,只是发了两次,两次都是我发的,不过你们竟然能这么快恢复也是让我眼前一亮,不和你聊了,我去 ...
这位鱼油,对不起,是我看错了,请接受我真诚的歉意
def task(w,n,c):
person={'Monday':'James','Tuesday':'John','Wednesday':'Robert','Thursday':'Michael','Friday':'William'}
per_today=person
print("It is %s today, %s, you have to work, you must spray %d trees and you need %d dollars to buy liquid" % (w,per_today,n,n*c))
[\code]
def task(w,n,c):
person={'Monday':'James','Tuesday':'John','Wednesday':'Robert','Thursday':'Michael','Friday':'William'}
per_today=person
print("It is %s today, %s, you have to work, you must spray %d trees and you need %d dollars to buy liquid" % (w,per_today,n,n*c))
lalalaoh 发表于 2017-8-11 21:40
def task(w,n,c):
person={'Monday':'James','Tuesday':'John','Wednesday':'Robert','Th ...
反斜杠改为正斜杠就是 code-style 了 新手·ing 发表于 2017-8-11 21:23
这位鱼油,对不起,是我看错了,请接受我真诚的歉意
不要客气了,感觉咱们论坛有这么快的回复速度,还是很温馨的,一起学习,一起进步{:5_91:} 我用字典存储- -
def task(w, n, c):
work = {
'Monday': 'James',
'Tuesday': 'John',
'Wednesday': 'Robert',
'Thursday': 'Michael',
'Friday': 'William'
}
x = 1 * n * c
return 'It is %s today, %s, you have to work, you must spray %d trees and you need %d dollars to buy liquid.' % (w, work, n, x)
为啥新人不给评分啊{:10_333:}评分不应该是每个人都应有的权利吗。。 shinemic 发表于 2017-8-12 09:53
为啥新人不给评分啊评分不应该是每个人都应有的权利吗。。
啊,我都给了吧 新手·ing 发表于 2017-8-12 10:03
啊,我都给了吧
我没表达好意思哈,我是说刚注册的号不能给别人评分,比如我看到不错的回帖也希望给他来个荣誉+x金币+x啥的,但好像没权限~ shinemic 发表于 2017-8-12 10:05
我没表达好意思哈,我是说刚注册的号不能给别人评分,比如我看到不错的回帖也希望给他来个荣誉+x金币+x啥 ...
你再多再论坛里多呆呆,多回回贴什么的,,
页:
[1]
2