0% found this document useful (0 votes)
14 views2 pages

Pyspark Assignment1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Pyspark Assignment1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1. What is the output of the following code?

nums =set([1,1,2,3,3,3,4,4])

print(len(nums))

A. 4

2. What will be the output?

d ={"john":40, "peter":45}print(list(d.keys()))

A.[‘john’,’peter’]

3. A website requires a user to input username and password to register. Write a program to check
the validity of password given by user. Following are the criteria for checking password:1. At least 1
letter between [a-z]2. At least 1 number between [0-9]1. At least 1 letter between [A-Z]3. At least 1
character from [$#@]4. Minimum length of transaction password: 65. Maximum length of
transaction password: 12Hint: In case of input data being supplied to the question, it should be
assumed to be a console input.4.Write a for loop that prints all elements of a list and their position in
the list.a = [4,7,3,2,5,9] Hint: Use Loop to iterate through list elements.

A. import re
def isValidPassword(password):
#Check Max length of the password
if len(password)>12:
return False
#Check Min length of password
if len(password)<7:
return False
#Check Atlease on lower case letter
if not (re.search(r'[a-z]',password)):
return False
#Check Atlease on Upper case letter
if not (re.search(r'[A-Z]',password)):
return False
#Check for atlease one Number
if not (re.search(r'[0-9]',password)):
return False
#Check atlease one character from #@$
if not (re.search(r'[#@$]',password)):
return False
return True
#Call the method
password = input("Enter a password: ")
if isValidPassword(password):
print("Password is valid.")
else:
print("Password is invalid. Ensure it meets all criteria.")
4.Write a for loop that prints all elements of a list and their position in the list.

a = [4,7,3,2,5,9]

A. a = [4,7,3,2,5,9]

for index, element in enumerate(a):

print(f"Position {index}: {element}")

You might also like