samedi 29 février 2020

Counting inputs in a for loop

The variable "countT" keeps adding after every input, even with the if statement that says to add 0 to "countT" it continues to do so. I tried doing, if temp <= 0: then it would also add nothing to "countT".

countT = 0
temp = 0
listT = []

breath = input("Do you have shortness of breath (y/n)? ")
cough = input("Do you have a cough(y/n)? ")
sorethroat_runnynose = input("Do you have a sore throat/runny nose (y/n)? ")
nausea = input("Do you have diarrhea, nausea and vomiting (y/n)? ")

if str.lower(breath)== 'y' and str.lower(cough)== 'y'and str.lower(sorethroat_runnynose)== 'n' and str.lower(nausea)== 'n':
    print("Enter 5 most recent temperature readings:")
    for x in range (1,6):
        temp2= int(input("Temp: "))
        temp += temp2
        listT.append(temp2)
        if temp == 0:
            countT +=0
        else:
            countT +=1

    avgT = (temp/countT) 

    print("Your max Temp was: ",(max(listT)))
    print("Average Temp is: ",avgT)
    print("You likely have the influenza virus")

    if avgT > 100 and temp > max(listT):
       print("Please seek medical attention now!") 

    elif avgT > 99:
        print("Monitor your condition closely!")

elif str.lower(breath)== 'n' and str.lower(cough)== 'n' and str.lower(sorethroat_runnynose)== 'n' and str.lower(nausea)== 'n':
    print("There are no symptoms but you should wait to see if you develop any.")

else:
    print("you likely have the influenza virus.")

Aucun commentaire:

Enregistrer un commentaire