新手·ing 发表于 2017-8-11 08:42:29

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:42:48

本帖最后由 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))

qwc3000 发表于 2017-8-11 11:32:48

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)))

woigh 发表于 2017-8-11 12:30:44

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:23:30

本帖最后由 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))

古堡主人。 发表于 2017-8-11 17:30:08

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'

古堡主人。 发表于 2017-8-11 17:31:26

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'

古堡主人。 发表于 2017-8-11 17:44:48

我只是试了一下怎么能把代码粘的像代码的样子{:10_249:},新手上路

新手·ing 发表于 2017-8-11 17:55:35

古堡主人。 发表于 2017-8-11 17:44
我只是试了一下怎么能把代码粘的像代码的样子,新手上路

{:10_295:}那也不要抄袭

古堡主人。 发表于 2017-8-11 21:18:11

新手·ing 发表于 2017-8-11 17:55
那也不要抄袭

没有抄袭,只是发了两次,两次都是我发的,不过你们竟然能这么快恢复也是让我眼前一亮,不和你聊了,我去学python了,学好之后才能爬草榴

新手·ing 发表于 2017-8-11 21:23:15

古堡主人。 发表于 2017-8-11 21:18
没有抄袭,只是发了两次,两次都是我发的,不过你们竟然能这么快恢复也是让我眼前一亮,不和你聊了,我去 ...

这位鱼油,对不起,是我看错了,请接受我真诚的歉意

lalalaoh 发表于 2017-8-11 21:40:40


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]

lalalaoh 发表于 2017-8-11 21:41:21


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))

shinemic 发表于 2017-8-11 22:18:46

lalalaoh 发表于 2017-8-11 21:40

def task(w,n,c):
      person={'Monday':'James','Tuesday':'John','Wednesday':'Robert','Th ...

反斜杠改为正斜杠就是 code-style 了

古堡主人。 发表于 2017-8-11 23:24:31

新手·ing 发表于 2017-8-11 21:23
这位鱼油,对不起,是我看错了,请接受我真诚的歉意

不要客气了,感觉咱们论坛有这么快的回复速度,还是很温馨的,一起学习,一起进步{:5_91:}

九九八十一 发表于 2017-8-12 09:51:08

我用字典存储- -
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)

shinemic 发表于 2017-8-12 09:53:26

为啥新人不给评分啊{:10_333:}评分不应该是每个人都应有的权利吗。。

新手·ing 发表于 2017-8-12 10:03:11

shinemic 发表于 2017-8-12 09:53
为啥新人不给评分啊评分不应该是每个人都应有的权利吗。。

啊,我都给了吧

shinemic 发表于 2017-8-12 10:05:11

新手·ing 发表于 2017-8-12 10:03
啊,我都给了吧

我没表达好意思哈,我是说刚注册的号不能给别人评分,比如我看到不错的回帖也希望给他来个荣誉+x金币+x啥的,但好像没权限~

新手·ing 发表于 2017-8-12 10:20:11

shinemic 发表于 2017-8-12 10:05
我没表达好意思哈,我是说刚注册的号不能给别人评分,比如我看到不错的回帖也希望给他来个荣誉+x金币+x啥 ...

你再多再论坛里多呆呆,多回回贴什么的,,
页: [1] 2
查看完整版本: Python:每日一题 76(答题领鱼币)