Py学习  »  Python

Python代码没有给出正确的结果

Riza • 5 年前 • 1369 次点击  

我对Python中的代码有问题。我需要把时间改成军事时间吗?我的代码没有返回正确的答案

问题是: 小时=3 分钟=45

#Around Georgia Tech, there are plenty of places to get a
#late night bite to eat. However, they have different hours,
#so when choosing where to go, you have to think about who's
#still open!
#
#Imagine you're choosing between the following restaurants:
#
# - Barrelhouse: Closes at 11:00PM
# - Taco Bell: Closes at 2:00AM
# - Cookout: Closes at 3:00AM
# - Waffle House: Never closes. Ever.
#
#Assume that this list is also a priority list: if Barrelhouse
#is open, you choose Barrelhouse. If not, you choose Taco Bell
#if it's open. If not, you choose Cookout if it's open. If
#not, you choose Waffle House.
#
#However, there are two wrinkles:
#
# - We're using 12-hour time.
# - hour will always represent a time from 10PM to 5AM.
#
#That means that if hour is 10 or 11, it's PM; if hour is
#12, 1, 2, 3, 4, or 5, it's AM. This will make your reasoning
#a little more complex. You may assume that all four
#restaurants open later than 6AM, though, so you don't have
#to worry about opening time, just closing time.
#
#Add some code below that will print what restaurant you'll
#go to based on the current values of hour and minute.

我的代码在这里

#Add your code here!

if hour == 12 and hour <= 5 and hour >= 1:
    print("Taco Bell" , "Cookout", "Waffle House")
elif hour > 5 and hour < 11:
    print("Waffle House" , "Barrelhouse")
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/53645
 
1369 次点击  
文章 [ 1 ]  |  最新文章 5 年前
divyang4481
Reply   •   1 楼
divyang4481    5 年前

你应该有以下流程才能得到餐厅的名单

list=[]

list.append("Waffle House")
if hour<=2 or hour>=6 :
    list.append("Taco Bell")

if hour<=3 or hour>=6:
    list.append("Cookout")

if hour<=11 and hour>=6:
    list.append("Barrelhouse")    

print(list)