While loop in python 😭😭😭😭😭😭 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

While loop in python 😭😭😭😭😭😭

The program first prompts for and reads in temperatures (all integers) until a line with no characters in received. It computes the average of all temperature readings. There need not be any readings at all because the first line itself may be empty. Your code should not fail even if there are no temperature readings. The code then reads unwind speeds. These are integers with values 0 or more. The sequence ends with the sentinel value of -1. The program computed the maximum of the wind speeds it reads. There need not be any readings at all because the first line itself maybe -1. Your code should not fail if there are no wind speed readings. The last set of readings is for humidity values (integers) between 0 and 100 (both values included) Any value outside this range is a sentinel value. The program computed the latest of the humidity readings. There need not be any readings at all because the first line itself may. E outside the range of 0 and 100. Your code should not fail even if there are no humidity readings. After all the readings, the program prints the average temperature, maximum wind speed, and the most recent humidity reading. If any of the readings is empty, the program prints an appropriate message as given below. No info on temperature No info on wind speed No info on humidity

23rd Mar 2019, 12:58 AM
Safina Nganga
Safina Nganga - avatar
7 Answers
+ 3
Sample input: 29 28 28 30 27 3 5 12 2 1 -1 67 89 98 12 56 200 Is this a valid input?
23rd Mar 2019, 1:51 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
If these are the inputs you are asking, here is my code: inp=' ' temps=[] speeds=[] humids=[] while True: a=input("Enter temperature (enter nothing to stop): ") try: inp=int(inp) temps.append(inp) except: if inp=='':break while True: a=input("Enter windspeed (enter -1 to stop): ") try: inp=int(inp) speeds.append(inp) except: if inp=='-1':break while True: a=input("Enter humidity (enter something out of range to stop): ") try: inp=int(inp) if inp<0 or inp>100:break humids.append(input) except: pass if len(temps)==0: print("No temperature inputs") else: print("Maximum temperature", max(temps)) if len(speeds)==0: print("No wind speeds inputs") else: print("Maximum wind speed:", max(speeds)) if len(humidity)==0: print("No humidity readings given") else: print("Maximum humidity:", max(humids))
23rd Mar 2019, 2:07 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
I'm first asking if this is the input you are asking for.
23rd Mar 2019, 1:56 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
what would be the code behind it?
23rd Mar 2019, 1:54 AM
Safina Nganga
Safina Nganga - avatar
0
that would be an example of an input yes
23rd Mar 2019, 2:02 AM
Safina Nganga
Safina Nganga - avatar
0
could it work for other inputs?
23rd Mar 2019, 2:14 AM
Safina Nganga
Safina Nganga - avatar