In: Computer Science
Ex. 1.Create a Python script . Write a program that goes through a tupple of numbers representing the temperatures taken at regular intervals in a day, at least 6 of them. The program should store this tupple in a variable, and then computing the average temperature. For that, use a for loop going over the temperature and adding all the values to a variable sum, initialized as 0. Then at the end, divide the sum by their count, and output a message communicating what the average temperature was on that day.
Ex. 2. Password verification Write a program that inputs a string from the user representing a password, and checks its validity. A valid password must contain: At least 1 lowercase letter (between 'a' and 'z') and 1 uppercase letter (between 'A' and 'Z'). At least 1 digit (between '0' and '9' and not between 0 and 9). At least 1 special character (hint: use an else to count all the characters that are not letters or digits). A minimum length 6 characters. No spaces (hint: when you encounter a space, you can break out of the loop). The program should output a message saying that the password is valid, or if it isn't valid, saying why not. For example, if the password has a length of 5, the output should say "The password is too short; a minimum of 6 characters required" and so on.
***************************Summmary*****************************
The code for above two questions is given below..with comments and output screenshot
Both the programs are provided with comments for explanation
I hope it works for you!!!!!!!!!!
*************************Program*************************
Q.1
sum=0  #intiazing sum equal to 0
count=0  #intializing count to 0
tuple=(37,39,40,42,41,38)  #tuple with 6 temperatures in a day
for i in tuple:    #for loop for going through tuple storing the temperature
  sum=sum+i        # adding number in tuple to sum
  count=count+1     #incrementing count to count the number of temperature in tuple
    
print("Today's Average temperature is ",float(sum/count))    # printing average temperature by dividing sum by count
Q.2
password=input("Enter the password")    #taking password from user
lower=0    #number of lowercase in string
upper=0    #number of uppercase in string
digit=0    # number of digits in string
spechar=0   # number of special character in string
if(len(password)>=6):    #if length is greater than or equal to 6
  for i in password:    #iterate through the characters in string
    if(i.islower()):    # if character is a lowercase then increase value of lower by 1
      lower+=1    
    elif(i.isupper()):  #if character is a uppercase then increase value of upperby 1
      upper+=1
    elif(i.isdigit()):   #if character is a digit then increment digit by 1
      digit+=1
    elif(i==' '):  #if character is a space
      printf("Password must not contain Space")
      break
    else:    #ifcharacter is not a lowercase ,uppercase ,digit and space then increase special character by 1
      spechar+=1    
  
  if(lower!=0 and upper!=0 and digit!=0 and spechar!=0):   
 # if everything is greater than 0 that means password is valid 
    print("Password is Valid")
  elif(lower==0):    #if lower is 0 that means there is no lowercase in string
    print("Password must contain at least 1 lowercase character")
  elif(upper==0):    #if upper is 0 that means there is no uppercase in string
    print("Password must contain at least 1 uppercase character")
  elif(digit==0):    #if digit is 0 that means there is no digit in string
    print("Password must contain at least 1 digit")
  elif(spechar==0):    #if spechar is 0 that means there is no special char in string
    print("Password must contain at least 1 special character")
else:    #if string length is less than 6 then password length is not valid
  print("Password length must be greater than or equal to 6")
*************************Output*************************

