Python函数问题,求大佬指导
First, def a function, shut_down, that takes one arguments. Don't forget the parentheses or the colon!
Then, if the shut_down function receives an s equal to "yes", it should return "Shutting down"
Alternatively, elif s is equal to "no", then the function should return "Shutdown aborted".
Finally, if shut_down gets anything other than those inputs, the function should return "Sorry"
谷歌的翻译如下:
首先,def一个函数,shut_down它需要一个参数 s。 不要忘记括号或冒号!
然后,如果shut_down函数接收到等于“ yes ”的 s,则应返回“ Shutting down ”
或者,elif等于"no",那么函数应该返回"Shutdown aborted"。
最后,如果shut_down得到除了这些输入之外的任何东西,该函数应该返回"Sorry"
def shut_down(s):
return s
if __:
return "Shutting down"
elif ___:
return "Shutdown aborted"
else:
return "Sorry"
试过几种。但是好像不行,求指导
Python函数问题,求大佬指导
你能用 python 和 flask 搭建 bbs 论坛 https://www.v2ex.com/t/361795#reply27,却连一个简单的 python 函数都不会写?
我无法理解你的问题
所有工作没回音,现在在从头学基础
从你贴出来的代码来看。你连 if 语句都不会用,根本不会编程。就好比学数学确不会算加减乘除法。
这个不是基础没学好了……这只是单纯的不会 Python 而已
好吧,我还是想问问这个条件应该怎么写才能通过
1, s = 'yes’
2, s = ‘no’
…
我也醉了。。。
1, s == ‘yes’
2, s == ‘no’
…
没缩进,看着眼睛疼
我想他说的意思是,你贴出的代码函数定义第一句就是 return,那后面的代码都没有必要了,因为根本不会执行。这种问题放在任何语言上都是问题。
def shut_down(s):
return s
def func():
if shut_down()==‘yes’:
return ‘Shutting down’
elif shut_down()==‘no’:
return ‘Shutdown aborted’
else:
return ‘Sorry’
我去。。没有缩进好难受。。。。
这就是原题。。shut_down 函数接收到的 s 为 yes 就 return “Shutting down”
但是这个就是原题。。我也没弄清楚
这种不行。。。这种早就试过了
这么写 return 根本不能返回
你的意思是说代码段也是题目的一部分?题目要求在横线处填空?
不是,代码是我自己写的,横线初填空是我感觉,题目说返回那个,我就直接返回了,然后就是我感觉判断语句写了好多遍都是错了
如果你说的是 https://www.codecademy.com/courses/python-beginner-c7VZg/4/1
我试着写了以下代码是可以工作的。
def shut_down(s):
if s == ‘yes’:
return ‘Shutting down’
elif s == ‘no’:
return ‘Shutdown aborted’
else:
return 'Sorry’
另,python 感觉很方便的样子,决定学一下。
def shut_down(s):
if s == “yes”:
return “Shutting down”
elif s == “no”:
return “shutdown aborted”
else:
return “Sorry”
…………………………………………………………………………
LZ 你用 flask 写了个那么漂亮的 blog,这个不会???
return {‘yes’: ‘Shutting down’, ‘no’: ‘Shutdown aborted’}.get(s, ‘Sorry’)
shut_down = lambda x: {“yes”: “Shutting down”, “no”: “shutdown aborted”}.get(x, “Sorry”)
你们在干嘛?
27 写得没问题。
我写的是 lambda 形式而已
她的意思是这样的
def shut_down(s):
····return {‘yes’: ‘Shutting down’, ‘no’: ‘Shutdown aborted’}.get(s, ‘Sorry’)
return 这种返回数据我就用来写过json,今天涨知识了,我想问问.get的效果能解释下吗
这很 pythonic
莫名其妙的问题。
惭愧惭愧,只会一般的写法,这种高端的写法,厉害


