Python Practical 180
Python Practical 180
Patil Pratishthan’s
D. Y. Patil Institute of Master of Computer Applications & Management
Sector No.29, Behind Akurdi Railway Station, Pradhikaran, Nigdi, Pune – 411044
Tel No: 020-27640998, 202737393, Fax no: 27653054,
Website: www.dypimca.ac.in, Email: [email protected]
(Approved by AICTE, Recognized by DTE, Mah.; Affiliated to SPPU)
2 Write a program to create new list ‘b’ which contains only initial
letters from given list
A=[‘Pune’,’Mumbai’,’Delhi’,’Nagpur’]
3 Write a program to print different vowels present in the word
"Learning python"?
4 Write a program to check whether the given number is even or odd?
5 Write a program to find maximum of 3 numbers using ternary
operator.
6 Write a program to display student score card with Student name,
No. of subjects, total , percentage, and grade.
7 Write a program to display student score card with Student name,
No. of subjects, total , percentage, and grade.
8 Write a program to print odd numbers between 0 to 100 using
continue statement
9 Write a program to take user inputs for list, set, tuple and dictionary
and display using for loop.
10 Write a program to add 10 employee names into list using for loop and
display list: append() or insert(index, value)
11 Write a program to print sum of numbers present inside list.
12 Write a program to check whether entered number is prime or not
13 Write a program to create list for basic salary of employee and
calculate the gross salary of an employee for following allowance
and deduction.
DA=25% , HRA=15%, PF=12%,TA=7,50%
Net Pay=basic+DA+HRA+TA
Gross Pay=Net Pay-PF
14 Write a program to access each character of string in forward and
backward direction using while loop.
15 Write a program to reverse the given string.
17 Write a program that accept the string from user and display the
same string after removing vowels from it.
18 Write a program to sort the characters of the string and first alphabet
symbols followed by numeric values.
input: B4A1D3
Output: ABD134
19 Write a program to find the number of occurrences of each character
present in the given String?
input: ABCABCABBCDE
output: A-3,B-4,C-3,D-1,E-1
Output –
2. Write a program to create new list ‘b’ which contains only initial letters from
given list A=[‘Pune’,’Mumbai’,’Delhi’,’Nagpur’]
Output –
Output –
5. Write a program to find maximum of 3 numbers using ternary operator. a, b,
c = 10, 20, 30
Output –
6. Write a program to display student score card with Student name, No. of
subjects, total , percentage, and grade.
student_name = "John"
num_subjects = 5 marks =
[85, 90, 78, 92, 88]
total_marks = sum(marks)
percentage = total_marks / (num_subjects * 100) * 100 grade = 'A'
if percentage >= 80 else 'B' if percentage >= 60 else 'C'
print(f"Name: {student_name}") print(f"No.
of subjects: {num_subjects}") print(f"Total
marks: {total_marks}") print(f"Percentage:
{percentage}%") print(f"Grade: {grade}")
Output –
7. Write a program to print odd numbers between 0 to 100 using continue
statement
for i in range(101):
if i % 2 == 0:
continue
print(i, end=' ')
Output –
8. Write a program to take user inputs for list, set, tuple and dictionary and
display using for loop.
# List
# Set
user_set = set(input("Enter elements of set separated by space: ").split())
print("Set:", user_set)
# Tuple
user_tuple = tuple(input("Enter elements of tuple separated by space:
").split()) print("Tuple:", user_tuple)
#Dictionary
user_dict =
{} while
True:
key = input("Enter key (or 'quit' to stop): ")
if key == 'quit':
break value =
input("Enter value: ")
user_dict[key] = value
print("Dictionary:", user_dict)
Output –
9. Write a program to add 10 employee names into list using for loop and
display list: append() or insert(index, value)
Output –
10. Write a program to print sum of numbers present inside list.
def sum_of_numbers(num_list):
total = 0
for num in num_list:
if isinstance(num, (int, float)):
total += num
return total
# Example usage:
numbers = [10, 20, 30, 40, 50]
print("Sum of numbers:", sum_of_numbers(numbers))
Output –
12. Write a program to create list for basic salary of employee and calculate the
gross salary of an employee for following allowance and deduction.
Output –
index += 1
print("\nBackward direction:")
index >= 0:
index -= 1
Output –
Output –
16. Write a program that accept the string from user and display the same
string after removing vowels from it.
Output –
17. Write a program to sort the characters of the string and first alphabet
symbols followed by numeric values.
input: B4A1D3
Output: ABD134
input_string = "B4A1D3"
alphabets = ''.join(sorted(char for char in input_string if char.isalpha())) numbers
= ''.join(sorted(char for char in input_string if char.isdigit()))
output_string = alphabets + numbers
print("Sorted output:", output_string)
Output –
input: ABCABCABBCDE
output: A-3,B-4,C-3,D-1,E-1
input_string = "ABCABCABBCDE"
char_count = {} for char in input_string:
char_count[char] = char_count.get(char, 0) + 1
for char, count in char_count.items():
print(f"{char}-{count}", end=", ")
Output –
19. Write a python program to calculate of percentage of the given list of
marks using Arbitrary argument
Output –
20. Write a Python function that accepts a string and counts the number of
upper and lower case letters. Eg: “Data Is Very Important”