code file
code file
Code –
s=input("Enter a string:")
test=False
dig="0123456789"
for ch in s:
if ch in dig:
print("The string contains a digit.")
test=True
break
if test==False:
print("The string doesn't contain a digit.")
PROGRAM 11
Output -
Enter a string:2fgdh
The string contains a digit.
Enter a string:ghfsj
The string doesn't contain a digit
PROGRAM 12
Q2. Write a program that inputs a line of text and
prints its each word in a separate line. Also, print the
count of words in the line
Code -
s=input("Enter a string:")
count=0
for word in s.split():
print(word)
count+=1
print("Total words:",count)
PROGRAM 12
Output -
Code –
val=[17,23,18,19]
print("The list is:",val)
while True:
print("Main menu")
print("1. Insert")
print("2. Delete")
print("3. Exit")
ch=int(input("Enter your choice 1/2/3:"))
if ch==1:
item=int(input("Enter item:"))
pos=int(input("Insert at which position"))
index=pos-1
val.insert(index,item)
print("Success! List now is:",val)
elif ch==2:
print("Deletion menu")
print("1. Delete using value")
print("2. Delete using index")
print("3. Delete a sublist")
dch=int(input("Enter choice(1/2/3):"))
if dch==1:
item=int(input("Enter item to be deleted"))
val.remove(item)
print("List now is : ", val)
elif dch == 2:
index= int(input("Enter index of item to be deleted :"))
val.pop(index)
print("List now is : ", val)
elif dch == 3:
l = int(input("Enter lower limit of list slice to be deleted:"))
h = int(input("Enter upper limit of list slice tobe deleted:"))
del val[1:h]
print("List now is : ", val)
else:
print("valid choices are 1/2/3 only.")
elif ch == 3:
break
else:
print("valid choices are 1/2/3 only.")
PROGRAM 13
Output
The list is: [17, 23, 18, 19]
Main menu
1. Insert
2. Delete
3. Exit
Enter your choice 1/2/3:1
Enter item:55
Insert at which position 4
Success! List now is: [17, 23, 18, 55, 19]
Main menu
1. Insert
2. Delete
3. Exit
Enter your choice 1/2/3:2
Deletion menu
1. Delete using value
2. Delete using index
3. Delete a sublist
Enter choice(1/2/3):1
Enter item to be deleted 17
List now is : [23, 18, 55, 19]
Main menu
1. Insert
2. Delete
3. Exit
Enter your choice 1/2/3:2
Deletion menu
1. Delete using value
2. Delete using index
3. Delete a sublist
Enter choice(1/2/3):2
Enter index of item to be deleted :1
List now is : [23, 55, 19]
Main menu
1. Insert
2. Delete
3. Exit
Enter your choice 1/2/3:2
Deletion menu
1. Delete using value
2. Delete using index
3. Delete a sublist
Enter choice(1/2/3):3
Enter lower limit of list slice to be deleted:1
Enter upper limit of list slice to be deleted:4
List now is : [23]
Main menu
PROGRAM 14
l=eval(input("Enter list:"))
length=len(l)
min_ele=l[0]
min_index=0
for i in range(1,length):
if l[i]<min_ele:
min_ele=l[i]
min_index=i
print("Given list is",l)
print("The minimum element of the given list is:")
print(min_ele,"at index",min_index)
PROGRAM 14
Output –
Enter list:[2,3,4,-2,6,-7,8,11,-9,11]
Given list is [2, 3, 4, -2, 6, -7, 8, 11, -9, 11]
The minimum element of the given list is:-9 at index 8
PROGRAM 15
Q5. Write a program to check if the elements in the
first half of a tuple are sorted in ascending order or
not.
Code –
Output –
Output –
Output –
Code –
Output –
How many friends?2
Enter details of friend 1
Name:Garry
Phone :8856725509
Friends dictionary is {'Garry': 8856725509}
Enter details of friend 2
Name:Rushi
Phone :7890334503
Friends dictionary is {'Garry': 8856725509, 'Rushi': 7890334503}
Menu
1. Display all friends
2. Add new friend
3. Delete a friend
4. Modify a phone number
5. Search for a friend
6. Sort on names
7. Exit
Enter your choice (1.7):1
{'Garry': 8856725509, 'Rushi': 7890334503}
Menu
1. Display all friends
2. Add new friend
3. Delete a friend
4. Modify a phone number
5. Search for a friend
6. Sort on names
7. Exit
Enter your choice (1.7):2
Enter details of new friend
Name:Manny
Phone :6785994739
Menu
1. Display all friends
2. Add new friend
3. Delete a friend
4. Modify a phone number
5. Search for a friend
6. Sort on names
7. Exit
Enter your choice (1.7):3
Friend Name to be deleted:Garry
8856725509 deleted
Menu
1. Display all friends
2. Add new friend
3. Delete a friend
4. Modify a phone number
5. Search for a friend
6. Sort on names
7. Exit
Enter your choice (1.7):4
Friend Name: Rushi changed Phone :7787938632
Menu
1. Display all friends
2. Add new friend
3. Delete a friend
4. Modify a phone number
5. Search for a friend
6. Sort on names
7. Exit
Enter your choice (1.7):5
Friend Name: Manny
Manny exists in the dictionary.
Menu
1. Display all friends
2. Add new friend
3. Delete a friend
4. Modify a phone number
5. Search for a friend
6. Sort on names
7. Exit
Enter your choice (1.7):6
{ Manny : 6785994739 Rushi : 7787938632 }
Menu
1. Display all friends
2. Add new friend
3. Delete a friend
4. Modify a phone number
5. Search for a friend
6. Sort on names
7. Exit
Enter your choice (1.7):7
PROGRAM 19
Write a program to create a dictionary with the roll
number, name and marks of n students in a class
and display the names of students who have marks
above 75.
Code –
Output –
Code –
Output –