Python:每日一题 76

2017-11-27 14:33:00
六月
来源:
http://bbs.fishc.com/thread-94217-1-1.html
转贴 593
今天的题目比较简单,也比较综合





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'




答案:


  1. def task(w,n,c):
  2.     dict = {'Monday': 'James', 'Tuesday': 'John', 'Wednesday': 'Robert',
  3.             'Thursday': 'Michael', 'Friday': 'William'}
  4.     return 'It is {} today, {}, you have to work, you must spray {} trees and you need {} dollars to buy liquid'.format(w,dict[w],n,c*n)
复制代码
发表评论
评论通过审核后显示。