Case Study I - Perform Various I/O operations using Python edureka
PySpark Certification
Introduction to Python for Apache Spark Case Study1
What will be the output?
Code :
nums =set([1,1,2,3,3,3,4,4,7,8,9,1,3,2,56])
print(len(nums))
Output:
8
nums =set([1,1,2,3,3,3,4,4])
print(len(nums))
Output:
4
What will be the output?
Code
d ={"john":40, "peter":45}
print(list(d.keys()))
Output:
['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: 6
5. Maximum length of transaction password: 12
Hint: In case of input data being supplied to the question, it should be assumed to be a console input
Code:
import re
p= input("Input your password ")
x = True
while x:
if (len(p)<6 or len(p)>12):
break
elif not re.search("[a-z]",p):
break
elif not re.search("[0-9]",p):
break
elif not re.search("[A-Z]",p):
break
elif not re.search("[$#@]",p):
break
elif re.search("\s",p):
break
else:
print("Valid Password")
print(p)
x=False
break
if x:
print("Not a Valid Password")
output:
input your password B@tyjnj123
Valid Password
B@tyjnj123
Write a for loop that prints all elements of a list and their position in the list.
code :
a = [4,7,3,2,5,9]
Answer:
a = [4,7,3,2,5,9]
for i in a:
print("Element: " + str(i) + " Index: "+ str(a.index(i)))
Output:
Element: 4 Index: 0
Element: 7 Index: 1
Element: 3 Index: 2
Element: 2 Index: 3
Element: 5 Index: 4
Element: 9 Index: 5
No comments