我正在尝试生成包含“国家名称”的输出,并预测其白天还是黑夜。面临着获取国家名称的挑战。
我试图通过将时间模块转换为列表来访问time.gmtime()的索引,并能够预测其白天还是黑夜
from time import gmtime, strftime
import time
print("International Institute of Weather Forecasting
AGENCY(IIWA)\nDay or Night Prediction Module")
print(time.gmtime())
"""convert the time to list and assign to my time variable """
mytime = list(time.gmtime())
print("so now you will get the time variables in a list:\n",mytime)
print(type(time.gmtime()))
print("Today complete time details as of now:",strftime("%a, %d %b %Y
%H:%M:%S +0000", gmtime()))
def weather_forcasting_day_night_prediction(mytime):
if (mytime[3] >= 18):
print("Its night:Officially declared by IIWA weather forcasting
station ")
else:
print("Its day:Officially declared by IIWA weather forcasting
station")
weather_forcasting_day_night_prediction(mytime)
Time_Module_predict_day_or_night.py
International Institute of Weather Forecasting AGENCY(IIWA)
Day or Night Prediction Module
time.struct_time(tm_year=2019, tm_mon=6, tm_mday=21, tm_hour=20,
tm_min=13, tm_sec=1, tm_wday=4, tm_yday=172, tm_isdst=0)
so now you will get the time variables in a list:
[2019, 6, 21, 20, 13, 1, 4, 172, 0]
<class 'time.struct_time'>
Today complete time details as of now: Fri, 21 Jun 2019 20:13:01
+0000
Its night:Officially declared by IIWA weather forcasting station
Process finished with exit code 0