gpt4 book ai didi

python - 简单逻辑 Python 3

转载 作者:行者123 更新时间:2023-11-28 20:42:53 28 4
gpt4 key购买 nike

嘿,所以我被困在这个问题上,不确定为什么我的代码不起作用。任何帮助表示赞赏。干杯。

Write a function alarm_clock(day, on_vacation) that takes an int day (encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat) and a boolean on_vacation and returns a string of the form "7:00" indicating when the alarm clock should ring. Weekdays, the alarm should be "7:00" and on the weekend it should be "10:00". Unless we are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off".

例如:

  • print(alarm_clock(1, False)) 给出 7:00
  • print(alarm_clock(0, True)) 给出 off

我有:

def alarm_clock(day, on_vacation):

'''Alarm Clock'''

if day in range(1-6) and on_vacation is True:
return '10:00'
elif day is 0 or 7 and on_vacation is True:
return 'off'
elif day in range(1-6) and on_vacation is False:
return '7:00'
elif day is 0 or 7 and on_vacation is False:
return '10:00'

最佳答案

if day in range(1-6) and on_vacation is True:

应该是

if day in range(1, 7) and on_vacation:

否则,range(1-6) 确实是 range(-5)

关于python - 简单逻辑 Python 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29892332/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com