In: Computer Science
USE PYTHON :
# Problem Set 04:
- Write a function to seek for all even numbers and odd numbers in
the middle of two number A and B. Print even and odd numbers in 1
and 2020 (including both these two numbers)
# Problem Set 05:
- A website requests an user to input his account password.
- Write a program to examize the validity of the password.
- The valid password must consists of:
- At least 1 letter in [a-z]
- At least 1 number in [0-9]
- At least a letter in [A-Z] (capital)
- At least one special letter in [$#@]
- At least 6 letters in total
- At most 12 letters in total
- The program can accept a list of passwords that are split by
commas.
- Print all valid passwords in a line and split by commas
- Examples:
- Input: ABd1234@1,a F1#,2w3E*,2We3345
- Output: ABd1234@1
In case of any queries, please revert back.
==================== CODE BELOW FOR QUESTION 4 WITH COMMENTS ======================
def get_even_odd(A,B):
#We use lists for this
odd_nums = []
even_nums = []
# Go over A and B, and store even and odd into respective lists
for i in range(A,B+1):
if i%2==0:
even_nums.append(i)
else :
odd_nums.append(i)
print("Even Numbers are :- ",end=" ")
for i in even_nums:
print(i,end=" ")
print()
print("Odd Numbers are :- ", end=" ")
for i in odd_nums:
print(i, end=" ")
get_even_odd(1, 20)
============== CODE BELOW FOR QUESTION 5 ======================
def check_val(string):
# Make some checks for number,capital Letter,normal Letter,special Character
numCheck = False
capitalLetter= False
smallLetter = False
specialLetter = False
# Now, check each letter in password and check validity
for letter in string:
if letter.islower() == True:
capitalLetter=True
elif letter.isupper() == True:
smallLetter = True
elif letter.isdigit() == True:
numCheck = True
else:
specialLetter = True
# If all these checks are passed, we check length and return True
if numCheck==True and capitalLetter==True and smallLetter==True and specialLetter==True:
if len(string)>=6 and len(string)<=12:
return True
return False
return False
def get_corr_pswd(string):
# Split the list
list_pswds = string.split(",")
for pswd in list_pswds:
# For each password, check validity and print
if check_val(pswd)==True:
print(pswd)
get_corr_pswd("ABd1234@1,a F1#,2w3E*,2We3345")
================ SCREENSHOTS BELOW ========================


