Name: Anonymous 2010-09-08 19:18
Weather prediction in Python 2.7
import random
filename = "weather.txt"
days = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
weather = ["Cloudy", "Raining", "Clear", "Snowing"]
def pred(value):
cl = "It's going to be either Cloudy or Clear tomorrow"
cloudy = "It's going to be Cloudy tomorrow"
clear = "It's going to be Clear tomorrow"
if cur_day in text:
if "clear" in text:
print cloudy
elif "raining" in text:
print cl
elif "snowing" in text:
print cl
elif "cloudy" in text:
print clear
else:
print random.choice(weather)
while 1 > 0:
cur_day = raw_input('Enter the current day: ')
cur_weath = raw_input('Raining/Snowing/Clear/Cloudy ')
day_weath = cur_day.lower() + " " + cur_weath.lower()
if cur_day in days:
break
else:
pass
old = open(filename, "r")
text = old.read()
FILE = open(filename,"w")
FILE.writelines(day_weath)
FILE.close()
pred(0)
import random
filename = "weather.txt"
days = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
weather = ["Cloudy", "Raining", "Clear", "Snowing"]
def pred(value):
cl = "It's going to be either Cloudy or Clear tomorrow"
cloudy = "It's going to be Cloudy tomorrow"
clear = "It's going to be Clear tomorrow"
if cur_day in text:
if "clear" in text:
print cloudy
elif "raining" in text:
print cl
elif "snowing" in text:
print cl
elif "cloudy" in text:
print clear
else:
print random.choice(weather)
while 1 > 0:
cur_day = raw_input('Enter the current day: ')
cur_weath = raw_input('Raining/Snowing/Clear/Cloudy ')
day_weath = cur_day.lower() + " " + cur_weath.lower()
if cur_day in days:
break
else:
pass
old = open(filename, "r")
text = old.read()
FILE = open(filename,"w")
FILE.writelines(day_weath)
FILE.close()
pred(0)