我现在准备在我组织即将举行的一个科学展览会上经营一个摊位。我正在帮助的booth围绕着使用Python实现手动过程和自动化。你知道吗
所有的展台都在采购自己的“好东西”,作为人们参观展台的奖励。你知道吗
我认为制作定制的Koozies是一个有趣的主意,它有一个Python脚本,可以创建一个函数来决定一个人是否应该使用Koozie。你知道吗
我基本上希望函数执行以下操作:
以下是我目前掌握的情况:
import datetime
from time import gmtime, strftime
def koozie_decider(temp):
if datetime.datetime.today().weekday() > 0 and datetime.datetime.today().weekday() < 5:
if int(strftime("%H", gmtime())) >= 21:
a = print("Outside of working hours - grab a koozie!")
else:
a = print("It's 5 o'clock somewhere - grab a koozie!")
else:
a = print("It's the weekend - grab a koozie!")
if temp >= 72:
b = print("And it's hot out - you're going to need one ASAP!")
else:
b = ""
return a, b
理想情况下,我可以消除对最后一个“else”语句的需要(当temp低于72时仍然不返回字符串)。有人知道我怎么做吗?你知道吗
我也想让你们用语法来解释。展会上的人对Python的了解会比我多,所以我希望代码尽可能高效。你知道吗
有没有什么低挂的水果,让这个功能更“Python”?你知道吗
你可以用很多不同的方法做很多事情。我很惊讶这个问题仍然悬而未决,不管怎么说,就像大家在评论中解释的那样,这样做毫无意义
a = print('something...')
如果您仍然不完全理解这里发生了什么,您可以问不同的问题,因为这意味着您不知道print函数(python3.x)是如何工作的。
这将看起来有点酷,因为反对给自己的温度。尽管位置仍然需要硬编码。你知道吗
修改代码koozie_decider。你知道吗
相关问题 更多 >
编程相关推荐