Cloudy w/ a Chance of Rain

Challenge

To help out your local meteorologist, you decide to write a sophisticated program that can determine the chance of rain for any given six hours. Hint: think about or's and and's in probability!

For each input, you will receive a space-separated array of integers (each between 0 and 100) that represent the percent chance of rain for each hour in a six hour period. Your program should return the percent chance (rounded down to the nearest integer) that it rains during any of those six hours.

Sample Input 1:5 93 83 28 100 8Sample Output 1:100

Sample Input 2:26 13 4 16 28 30Sample Output 2:73

Notes:

  • the inputs will be passed in (through stdin) separated by newlines; make sure your output (returned on stdout) is also separated by newlines
  • the first line of input will contain only one integer representing the number of additional lines of input you will receive

Solution

def main():

    number_of_days = int(input())

    chances_of_rain_list = []

    for day in range(number_of_days):

        hourly_chances_of_rain = input()  # Ex.: 5 93 83 28 100 8

        chances_of_no_rain = 1

        for hour in hourly_chances_of_rain.split(" "):

            prob = 1 - int(hour)/100
            chances_of_no_rain = chances_of_no_rain * prob

        chances_of_rain = int((1 - chances_of_no_rain) * 100)
        chances_of_rain_list.append(chances_of_rain)

    for prob in chances_of_rain_list:
        print(prob)


main()