Skip to content

Instantly share code, notes, and snippets.

@mayankdawar
Created February 19, 2020 17:31
Show Gist options
  • Save mayankdawar/f51adcde0f8c0f85440fc4e88ce7da13 to your computer and use it in GitHub Desktop.
Save mayankdawar/f51adcde0f8c0f85440fc4e88ce7da13 to your computer and use it in GitHub Desktop.
Create an empty list called resps. Using the list percent_rain, for each percent, if it is above 90, add the string ‘Bring an umbrella.’ to resps, otherwise if it is above 80, add the string ‘Good for the flowers?’ to resps, otherwise if it is above 50, add the string ‘Watch out for clouds!’ to resps, otherwise, add the string ‘Nice day!’ to res…
percent_rain = [94.3, 45, 100, 78, 16, 5.3, 79, 86]
resps = []
for i in percent_rain:
if i > 90:
resps.append("Bring an umbrella.")
elif i >80:
resps.append("Good for the flowers?")
elif i > 50:
resps.append("Watch out for clouds!")
else:
resps.append("Nice day!")
@asad-debug
Copy link

percent_rain = [94.3, 45, 100, 78, 16, 5.3, 79, 86]
resps = []
for i in percent_rain:
if i > 90:
resps += ['Bring an umbrella.']

elif i > 80:
    resps += ['Good for the flowers?']
    
elif i > 50:
    resps += ['Watch out for clouds!']
    
else:
    resps +=['Nice day!']
    
    print(resps)

This works 100%

@misspage
Copy link

I tried this but it did not work; not sure what is wrong

percent_rain = [94.3, 45, 100, 78, 16, 5.3, 79, 86]

resp =[]

if percent_rain < 90:
resp = ("bring an umbrella")
output (resp)
elif percent_rain > 80:
output (resp + ("Good for the flowers?"))
elif percent_rain<50:
output (resp +("Wacth out for clouds"))
else :
output (resp +("Nice day!"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment