Share 1st pu Lab Programs
Share 1st pu Lab Programs
2. Write a program to enter two integers and perform all arithmetic operations on them.
3. Write a Python program to accept length and width of a rectangle and compute its perimeter and
area.
1|Page
4. Write a Python program to calculate the amount payable if money has been lent on simple interest.
Principal or money lent = P, Rate of interest = R% per annum and Time = T years. Then Simple Interest
(SI) = (P x R x T)/ 100. Amount payable = Principal + SI. P, R and T are given as input to the program.
5. Write a Python program to find largest among three numbers. (Make use of only if statement)
print(“The value of A is ”, a)
print(“The value of B is ”, b)
print(“The value of C is ”, c)
6. Write a program that takes the name and age of the user as input and displays a message whether
the user is eligible to apply for a driving license or not. (the eligible age is 18 years).
2|Page
7. Write a program that prints minimum and maximum of five numbers entered by the user. (Hint: Use
nested If statements only)
minimum = num1
maximum = num1
if num2 < minimum:
minimum = num2
else: if num2 > maximum:
maximum = num2
if num5< minimum:
minimum = num5
else: if num5 > maximum:
maximum = num5
8. Write a program to find the grade of a student when grades are allocated as given in the table
below.
Percentage of Marks Grade
Above 90% A
80% to 90% B
70% to 80% C
60% to 70% D
Below 60% E
Percentage of the marks obtained by the student is input to the program. (Hint: Use if…elif statement
only)
3|Page
elif percentage >= 70:
grade = 'C'
elif percentage >= 60:
grade = 'D'
else:
grade = 'E'
print("Grade:", grade)
9.Write a function to print the table of a given number. The number has to be entered by the user.
(Hint: Use for loop only)
def print_multiplication_table(number):
print("Multiplication Table for", number, ":")
for i in range(1, 11):
result = number * i
print(number, "x", i, "=", result)
number = int(input("Enter the number: "))
print_multiplication_table(number)
10. Write a program to find the sum of digits of an integer number, input by the user. (Hint: Use
While loop only)
11. Write a program to check whether an input number is a palindrome or not. (Hint: Can’t use
slicing operation)
4|Page
12. Write a program to print the following patterns:
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
13. Write a program that uses a user defined function that accepts name and gender (as M for Male, F
for Female) and prefixes Mr./Ms. based on the gender.
14. Write a program to input line(s) of text from the user until enter is pressed. Count the total number
of characters in the text (including white spaces), total number of alphabets, total number of digits, total
number of special symbols and total number of words in the given text. (Assume that each word is
separated by one space).
total_characters = 0
total_alphabets = 0
total_digits = 0
total_special_symbols = 0
total_words = 0
print("Enter text (Press Enter to finish):")
while True:
line = input()
if line == "":
break
total_characters += len(line)
total_words += len(line.split())
for char in line:
if char.isalpha():
total_alphabets += 1
elif char.isdigit():
total_digits += 1
else:
5|Page
total_special_symbols += 1
print("\nResults:")
print("Total Characters:", total_characters)
print("Total Alphabets:", total_alphabets)
print("Total Digits:", total_digits)
print("Total Special Symbols:", total_special_symbols)
print("Total Words:", total_words)
15. Write a user defined function to convert a string with more than one word into title case string
where string is passed as parameter. (Title case means that the first letter of each word is capitalized)
def to_title(input_string):
words = input_string.split()
title_case_string = ' '.join(word.capitalize() for word in words)
return title_case_string
input_string = input("Enter a string: ")
result = to_title(input_string)
print("Title case string:", result)
16. Write a function that takes a sentence as an input parameter where each word in the sentence is
separated by a space. The function should replace each blank with a hyphen and then return the
modified sentence.
def replace_blank_with_hyphen(sentence):
modified_sentence = sentence.replace(' ', '-')
return modified_sentence
user_input = input("Enter a sentence with words separated by spaces: ")
modified_result = replace_blank_with_hyphen(user_input)
print("Original Sentence:", user_input)
print("Modified Sentence:", modified_result)
17.Write a program to find the number of times an element occurs in the list.
18.Write a function that returns the largest element of the list passed as parameter.
def find_largest_element(input_list):
if not input_list:
return None
largest = input_list[0]
for element in input_list:
if element > largest:
largest = element
6|Page
return largest
user_list = eval(input("Enter a list of elements: "))
largest_element = find_largest_element(user_list)
if largest_element is not None:
print("The largest element in the list is:", largest_element)
else:
print("The list is empty.")
19.Write a program to read email IDs of n number of students and store them in a tuple. Create two
new tuples, one to store only the usernames from the email IDs and second to store domain names from
the email IDs. Print all three tuples at the end of the program. [Hint: You may use the function split()]
20. Write a program to input names of n students and store them in a tuple. Also, input a name from
the user and find if this student is present in the tuple or not.
7|Page
8|Page