Assignment 2 1
Assignment 2 1
nums = set([1,1,2,3,3,3,4,4])
print(len(nums))
Output-4
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
import re
p= input("Please Enter 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")
x=False
break
if x:
print("Not a Valid Password")
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]
for i in a:
print((i),a.index(i))
5.Please write a program which accepts a string from console and print the
characters that have even indexes.
x=str(input("Enter the comment"))
y=""
for i in range(len(x)):
if i%2==0:
y=y+x[i]
print(y)
6.Please write a program which accepts a string from console and print it in
reverse order.
print(x[::-1])
7.Please write a program which count and print the numbers of each character in a
string input by console.
y={}
for i in x:
if i in y.keys():
y[i]+=1
else:
y[i]=1
print(y)
lists1= [1,3,6,78,35,55]
lists2=[1,24,35,24,88,120,155]
lists3=[]
for i in lists1:
if i in lists2:
lists3.append(i)
print(lists3)
x=[12,24,35,24,88,120,155,88,120,155]
y=set()
for i in x:
if i is not y:
y.add(i)
print(y)
10.By using list comprehension, please write a program to print the list after
removing the value 24 in [12,24,35,24,88,120,155
x=[12,24,35,24,88,120,155]
y=set()
for i in x:
if i is not 24:
y.add(i)
print(y)
11.By using list comprehension, please write a program to print the list after
removing the 0th,4th,5th numbers in [12,24,35,70,88,120,155].
x=[12,24,35,70,88,120,155]
print(x.remove(x[0]),x.remove (x[3]),x.remove(x[3]))
print(x)
12.By using list comprehension, please write a program to print the list after
removing delete numbers which are divisible by 5 and 7 in [12,24,35,70,88,120,155].
x=[12,24,35,70,88,120,155]
y=[]
for i in x:
if i%5==0 and i%7==0:
continue
else:
y.append(i)
print(y)
13. Please write a program to randomly generate a list with 5 numbers, which are
divisible by 5 and 7 , between 1 and 1000 inclusive.
y=[]
for i in range (5):
x = int(input("Enter 5 number which sould be between 1 and 1000"))
if 1<x<1000:
if x%5==0 and x%7==0:
y.append(x)
else:
print("enter the correct value")
break
else:
print("enter the correct value")
break
print(y)
x=x+1
print(y)