Q1.
import re
password = input("Input your password:")
x = True
while x:
if (len(password) < 6 or len(password) > 16):
break
elif not re.search("[a-z]", password):
break
elif not re.search("[0-9]", password):
break
elif not re.search("[A-Z]", password):
break
elif not re.search("[$#@]", password):
break
else:
print("Valid Password")
x = False
break
if x:
print("Not a Valid Password")
Q2.
string =input("Enter a string:")
count = 0
for i in string:
count = count + 1
string2 = string[ 0:2 ] + string [count - 2: count ]
print("Entered string = " + string)
print("New String = "+ string2)
Q3.
str1=input("Enter a string:")
str2=''
for i in str1:
str2=i+str2
if(str1==str2):
print("Palindrome")
else:
print("Not a palindrome")
Q4.
string=input("Enter a string:")
print(string)
char_freq={}
for i in string:
if i in char_freq:
char_freq[i]=char_freq[i]+1
else:
char_freq[i] = 1
result= max(char_freq, key = char_freq.get)
print("Most frequent character: ",result)
Q5.
totalTestcases = int(input("Total number of test cases: "))
for i in range(1, totalTestcases + 1):
maxCookies = int(input("Max cookies chef cooked: "))
m=0
cookies_in_pack = 0
for A in range(1, maxCookies + 1):
l = maxCookies % A
if m <= l:
m=l
cookies_in_pack = A
print("Cookies for chef:", m, "for test case", i)
print("Cookies packed in 1 pack:", cookies_in_pack, "for test case", i)
totalPacks = (maxCookies - m) // cookies_in_pack
print("Total packed packs are", totalPacks)
Q1.
num = int(input("Enter a number:"))
order = len(str(num))
sum = 0
temp = num
while temp > 0:
dig = temp % 10
sum = sum + dig ** order
temp = temp//10
if (num == sum):
print(num,"is an Armstrong Number")
else:
print(num,"is not an Armstrong Number")
Q2.
def check(str) :
str = str.lower()
vowels = set("aeiou")
s = set({})
for a in str :
if a in vowels :
s.add(a)
else:
pass
if len(s) == len(vowels) :
print("Accepted")
else :
print("Not Accepted")
str =input("Enter a string:")
check(str)
Q3.
with open(f"c:/Users/sprin/OneDrive/Desktop/231228_3.py", "r") as f:
d=0
for k in f:
w=k.split()
for i in w:
if len(i)==4:
d+=1
else:
pass
print("Number of words with four letters in the List: ",d)
Q4.
first=input("Enter file path which contain information: ")
second=input("Enter file path where you want to copy information: ")
with open(first,"r") as f:
content=f.read()
with open(second,"w") as x:
x.write(content)
print("SUCCEFULLY COPIED!!")
Q5.
fName=input("enter files name: ")
with open(fName,"r") as x:
print(" name hourlyWages hourWorked totalWage")
for line in x:
a,b,c=line.split(',')
b=float(b)
c=float(c)
print(" %-19s %-10.2f %-10.2f %10.2f " %(a,b,c,c*b) )
Q1.
#Python program to remove duplicate elements from list
lst = []
len_list = int(input("Enter length of list: "))
for i in range (len_list):
element = input("Enter an element: ")
lst.append(element) # Adding element in the list
print("Your created list is: ", lst)
for i in lst:
duplicate = lst.count(i) # counting no. of duplicates
if duplicate>1:
k = lst.index(i)
lst.pop(k) #Removing element
print("List without duplicate elements: ", lst)
Q2.
lst = [1, 1, 2, 3, 4, 4, 5, 1]
print(lst)
len_list =len( lst)
for i in range (len_list-1):
if lst[i] == lst[i+1]:
print(2 ,lst[i])
else:
print(1 ,lst[i])
print(1,lst[len_list-1])
Q3.
#Program to split the list
lst = []
lst1= []
lst2 = []
len_list = int(input("Enter length of list: "))
for i in range (len_list):
element = input("Enter elements: ")
lst.append(element) #creating list
l = int (input("Enter from where you want to split: "))
for i in range(l):
lst1.append(lst[i])
for i in range (l,len_list):
lst2.append(lst[i])
print("List after splitting : ",lst1, lst2) #print both lists
Q4.
#Program to rotate the list
lst = []
final_list =[]
len_lst = int(input("Enter length of lst: "))
for i in range (len_lst):
element = input("Enter element: ")
lst.append(element) # taking input for lst
rotate_num= int(input("Entrer position from where you want to rotate list: ")) #take input for index
from where we have to rotate it
for i in range(rotate_num, len_lst):
final_list.append(lst[i])
for i in range(rotate_num):
final_list.append(lst[i])
print("List after rotation: ", final_list) #print rotated list
Q5.
color_1 = []
color_2 = []
color_3 = []
len_color_1 = int(input("Enter length of color_1: ")) #4
len_color_2 = int(input("Enter length of color_2: ")) #4
len_color_3 = int(input("Enter length of color_3: ")) #4
for i in range (len_color_1):
element_1 = input("Enter elements in color1: ")
color_1.append(element_1) #Entering elements in list color2
for i in range (len_color_2):
element_2 = input("Enter elements in color2: ")
color_2.append(element_2) #Entering elements in list color2
for i in range (len_color_3):
element_3 = input("Enter element in color3: ")
color_3.append(element_3) #Entering elements in list color3
#Checking same element's order
k=min(len_color_1,len_color_2)
for i in range(0,k):
if(color_1[i]==color_2[i]):
print("TRUE")
break;
else:
print("FALSE")
break;
l=min(len_color_2,len_color_3)
for i in range(0,l):
if(color_2[i]==color_3[i]):
print("TRUE")
break;
else:
print("FALSE")
break;
m=min(len_color_1,len_color_3)
for i in range(0,m):
if(color_1[i]==color_3[i]):
print("TRUE")
break;
else:
print("FALSE")
break;