importhw4_utilif__name__=="__main__":# initialize variablesstrength=0report=""# Debugging#user_password = "AdmIn123%^%*(&"#user_password = "jaX1234"# get user inputuser_password=str(input("Enter a password => ").strip())# print the password for testing purposesprint(user_password)# get the length of the passwordlength=len(user_password)# check the length of the password and update strength and report accordinglyiflength<=7andlength>=6:strength+=1report+="Length: +1\n"eliflength>=8andlength<=10:strength+=2report+="Length: +2\n"eliflength>10:strength+=3report+="Length: +3\n"# count the number of uppercase and lowercase letters in the passwordnum_upper=sum(1forcinuser_passwordifc.isupper())num_lower=sum(1forcinuser_passwordifc.islower())# check the number of uppercase and lowercase letters and update strength and report accordinglyifnum_upper>=2andnum_lower>=2:strength+=2report+="Cases: +2\n"elifnum_upper>=1andnum_lower>=1:strength+=1report+="Cases: +1\n"# count the number of digits in the passwordnum_digits=sum(1forcinuser_passwordifc.isdigit())# check the number of digits and update strength and report accordinglyifnum_digits>=2:strength+=2report+="Digits: +2\n"elifnum_digits>=1:strength+=1report+="Digits: +1\n"# check for special characters and update strength and report accordinglyifany(cin"!@#$"forcinuser_password):strength+=1report+="!@#$: +1\n"ifany(cin"%^&*"forcinuser_password):strength+=1report+="%^&*: +1\n"# check for a specific pattern and update strength and report accordinglyif(num_upper+num_lower)==3andnum_digits==4andlen(user_password)>3:check=user_password.replace(user_password[0:3],"")ifsum(1forcincheckifc.isdigit())==4:strength-=2report+="License: -2\n"# check if the password is in the top 10,000 most common passwords and update strength and report accordinglyifuser_password.lower()inhw4_util.part1_get_top():strength-=3report+="Common: -3\n"# add the combined score to the reportreport+="Combined score: "+str(strength)+"\n"# check the strength and add the appropriate message to the reportifstrength<=0:report+="Password is rejected"elifstrength>=1andstrength<=2:report+="Password is poor"elifstrength>=3andstrength<=4:report+="Password is fair"elifstrength>=5andstrength<=6:report+="Password is good"elifstrength>=7:report+="Password is excellent"# print the reportprint(report)
importhw4_util"""
hw4_util.part2_get_week(1)[0] ==> ['AK',\
731545, 189, 147, 128, 132, 106, 125,\
118, 3373, 3819, 6839, 4984, 6045,\
6140, 1688]
"""deffind_state(states,state):state=state.upper()found_status=Falseforiinstates:ifi[0].upper()==state:found_status=Truereturniifnotfound_status:return[]defget_postive_per_100k(status):population=status[1]total_postive=0foriinrange(2,9):total_postive+=status[i]postive_per_100k=((total_postive/7)/population)*100000returnpostive_per_100kdefget_pct_postive_tests(status):num_tested=0num_postive=0foriinrange(2,16):num_tested+=status[i]foriinrange(2,9):num_postive+=status[i]pct_postive_tests=num_postive/num_testedreturnpct_postive_testsdefaction_valid(request_code):request_code=request_code.lower()allowed_action=["daily","pct","quar","high"]ifrequest_codeinallowed_action:returnTrueelse:returnFalsedefquar(week):states=[]foriinweek:ifget_postive_per_100k(i)>=10orget_pct_postive_tests(i)>=0.1:states.append(i[0])states.sort()returnstatesdefhigh(week):highest=""highest_value=0foriinweek:ifget_postive_per_100k(i)>highest_value:highest=i[0]highest_value=get_postive_per_100k(i)returnhighest.upper()defshow_high(week):highest=high(week)highest_postive_per_100k=get_postive_per_100k(find_state(week,highest))print("State with highest infection rate is",highest)print("Rate is {:.1f} per 100,000 people".format(highest_postive_per_100k))if__name__=="__main__":index_week=0# Initialize index_weekprint("...")whileindex_week!=-1:# Get index of weekindex_week=input("Please enter the index for a week: ").strip()print(index_week)index_week=int(index_week)# Stop if the index is -1ifindex_week<0:break# Get the week, check if the week is validweek=hw4_util.part2_get_week(index_week).copy()ifweek==[]:print("No data for that week")print("...")continue# Get the Actionrequest_code=input("Request (daily, pct, quar, high): ").strip()print(request_code)request_code=request_code.lower()# Check if the action is validifnotaction_valid(request_code):print("Unrecognized request")print("...")continue# Perform the actionifrequest_code=="daily":state=input("Enter the state: ").strip()print(state)state=state.upper()iffind_state(week,state)==[]:print("State {} not found".format(state))print("...")else:state_data=find_state(week,state)print("Average daily positives per 100K population: {:.1f}".format(get_postive_per_100k(state_data)))print("...")elifrequest_code=="pct":state=input("Enter the state: ").strip()print(state)state=state.upper()iffind_state(week,state)==[]:print("State {} not found".format(state))print("...")else:state_data=find_state(week,state)print("Average daily positive percent: {:.1f}".format(get_pct_postive_tests(state_data)*100))print("...")elifrequest_code=="quar":print("Quarantine states:")hw4_util.print_abbreviations(quar(week))print("...")elifrequest_code=="high":show_high(week)print("...")