Question

In: Computer Science

Ex. 1.Create a Python script . Write a program that goes through a tupple of numbers...

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.

Solutions

Expert Solution

***************************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*************************


Related Solutions

Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers...
Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers from the user until they enter a 0 and computes the product of all these numbers and outputs it. Hint: use the example from the slides where we compute the sum of a list of numbers, but initialize the variable holding the product to 1 instead of 0. print("Enter n") n = int(input()) min = n while n != 0: if n < min:...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program:...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program: Your program will create a username of your choice using a Kali Linux command "useradd -m mark", then set the password for that user using the Kali Linux Command "echo "mark:10101111" | chpasswd". Then you create a dictionary file using the Kali Linux command "crunch 8 8 01 > mylist.txt" Your python script should crack the password for that user and display on the...
Create this on Python Write a program that asks for three numbers. Check first to see...
Create this on Python Write a program that asks for three numbers. Check first to see that all numbers are different. If they’re not different, then exit the program. Otherwise, display the largest number of the three. Outputs: - Enter the first number: 4 - Enter the second number: 78 - Enter the third number: 8 (The largest number is 78.) Tasks - Complete the algorithm manually without using any built-in functions to find the largest number on list. -...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100 to a list (in order). Then remove the multiples of 3 from the list. Print the remaining values. b/ Write a program that initializes a list with ten random integers from 1 to 100. Then remove the multiples of 3 and 5 from the list. Print the remaining values. Please show your work and explain. Thanks
Write a java program creating an array of the numbers 1 through 10. Shuffle those numbers....
Write a java program creating an array of the numbers 1 through 10. Shuffle those numbers. Randomly pick a number between one and ten and then sequentially search the array for that number. Once the number is found, place that number at the top of the list. Print the list. Perform #3 thru #5 ten times.
using python 3 2. Write a python program that finds the numbers that are divisible by...
using python 3 2. Write a python program that finds the numbers that are divisible by both 2 and 7 but not 70, or that are divisible by 57 between 1 and 1000. 3. Write a function called YesNo that receives as input each of the numbers between 1 and 1000 and returns True if the number is divisible by both 2 and 7 but not 70, or it is divisible by 57. Otherwise it returns False. 4. In your...
using python 3 2. Write a python program that finds the numbers that are divisible by...
using python 3 2. Write a python program that finds the numbers that are divisible by both 2 and 7 but not 70, or that are divisible by 57 between 1 and 1000. 3. Write a function called YesNo that receives as input each of the numbers between 1 and 1000 and returns True if the number is divisible by both 2 and 7 but not 70, or it is divisible by 57. Otherwise it returns False. 4. In your...
1. What is a Python script? 2. Explain what goes on behind the scenes when your...
1. What is a Python script? 2. Explain what goes on behind the scenes when your computer runs a Python program.
Write a Python loop that goes through the list and prints each string where the string...
Write a Python loop that goes through the list and prints each string where the string length is three or more and the first and last characters of the strings are the same. Test your code on the following three versions of the list examples: examples = ['abab', 'xyz', 'aa', 'x', 'bcb'] examples = ['', 'x', 'xy', 'xyx', 'xx'] examples = ['aaa', 'be', 'abc', 'hello'].
Solve please in python b) Create a program that shows a series of numbers that start...
Solve please in python b) Create a program that shows a series of numbers that start at a and increase from 5 to 5 until reaching b, where a and b are two numbers captured by the user and assumes that a is always less than b. Note that a and b are not necessarily multiples of 5, and that you must display all numbers that are less than or equal to b. c) Create a program that displays n...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT