Building Simulation/Interaction using Lists and Iteration Hacks
starwarsmovies = {
'Name': ["The Phantom Menace", "Attack of the Clones", "Revenge of the Sith", "A New Hope", "Empire Strikes Back", "Return of the Jedi", "The Force Awakens", "The Last Jedi", "The Rise of Skywalker"],
'Audience': [59, 56, 66, 96, 97, 94, 85, 42, 86],
'Rotten Tomatoes': [51, 65, 79, 93, 94, 83, 93, 91, 52],
'Duration': [133, 143, 140, 121, 124, 133, 136, 152, 142],
'money made(millions)':[431, 302, 380, 307, 209, 252, 936, 620, 515]
}
moviesbymoney = sorted(zip(starwarsmovies['Name'], starwarsmovies['money made(millions)']), key=lambda x: x[1], reverse=True)
for movie in moviesbymoney:
print(f"{movie[0]}: ${movie[1]} million dollars")
import random
weather = ['sunny', 'cloudy', 'raining', 'snowing']
time = ['morning', 'afternoon', 'night']
yieldofcrops = {
('sunny', 'morning'): 70,
('sunny', 'afternoon'): 100,
('sunny', 'night'): 60,
('cloudy', 'morning'): 65,
('cloudy', 'afternoon'): 80,
('cloudy', 'night'): 50,
('raining', 'morning'): 40,
('raining', 'afternoon'): 50,
('raining', 'night'): 20,
('snowing', 'morning'): 10,
('snowing', 'afternoon'): 15,
('snowing', 'night'): 5,
}
weathertoday = random.choice(weather)
timenow = random.choice(time)
yieldtoday = yieldofcrops[(weathertoday, timenow)]
if yieldtoday >= 70:
cropresult = "very good"
elif yieldtoday >= 40:
cropresult = "good"
elif yieldtoday >= 20:
cropresult = "bad"
else:
cropresult = "very bad"
print(f"This {timenow}, the weather was {weathertoday} and the crop yield was {cropresult}.")