Lab Manual 1st Year (Updated)
Lab Manual 1st Year (Updated)
1 PU LAB MANUAL
COMPUTER SCIENCE
Practical Exam Scheme:
PART – A
Output:
Output:
Output:
enter the length : 25
enter the breadth: 10
area of rectangle= 250.0
perimeter of rectangle= 70.0
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.
Output:
Output:
enter the first number : 3
enter the second number : 7
enter the third number : 5
the largest among three is : 7
6. Write a Python 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).
Output:
enter the name: Deekshit
enter the age: 23
name= Deekshit
age= 23
Eligible
7. Write a program that prints minimum and maximum of five
numbers entered by the user.
smallest = 0
largest = 0
for a in range(0,5):
x = int(input("Enter the number: "))
if a == 0:
smallest = largest = x
if(x < smallest):
smallest = x
if(x > largest):
largest = x
print("The smallest number is", smallest)
print("The largest number is ", largest)
Output:
print("grade=:", grade)
Output:
Enter the percentage = 94.4
grade=: A
Output:
Output:
Output:
12345
1234
123
12
1
rows=5
for i in range(rows, 0, -1):
for j in range(1, i+1):
print(j, end=" ")
print()
Output:
12345
1234
123
12
1
PART - B
Chapter 7: Functions
Output:
def calculate_discriminant_and_result():
a = float(input("Enter coefficient a: "))
b = float(input("Enter coefficient b: "))
c = float(input("Enter coefficient c: "))
discriminant=b**2 - 4*a*c
if discriminant > 0:
result = "The discriminant is positive. The quadratic equation
has two distinct real roots."
elif discriminant == 0:
result = "The discriminant is zero. The quadratic equation has
one real root (a repeated root)."
else:
result = "The discriminant is negative. The quadratic equation
has no real roots."
return discriminant, result
print("Discriminant:", discriminant_result)
print("Result:", message)
Output:
Enter coefficient a: 1
Enter coefficient b: 2
Enter coefficient c: 1
Discriminant: 0.0
Result: The discriminant is zero. The quadratic equation has one real ro
ot (a repeated root)
Enter coefficient a: 2
Enter coefficient b: -3
Enter coefficient c: 1
Discriminant: 1.0
Result: The discriminant is positive. The quadratic equation has two dist
inct real roots.
Enter coefficient a: 2
Enter coefficient b: -2
Enter coefficient c: 1
Discriminant: -4.0
Result: The discriminant is negative. The quadratic equation has no real
roots.
15. Write a program with a user-defined function that accepts
two numbers as parameters, swaps them if the first is less than
the second, and returns the numbers in the new or same order.
Ouput:
total_characters = 0
total_alphabets = 0
total_digits = 0
total_special_symbols = 0
total_words = 0
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)
Ouput:
Results:
Total Characters: 26
Total Alphabets: 19
Total Digits: 1
Total Special Symbols: 6
Total Words: 7
17. Write a user-defined function to convert a string with
more than one word into title case, where the string is passed
as a parameter. (Title case means the first letter of each word is
capitalized.)
def convert_to_title_case(input_string):
title_case_string = ""
capitalize_next = True
for char in input_string:
if capitalize_next and char.isalpha():
title_case_string += char.upper()
capitalize_next = False
else:
title_case_string += char.lower()
if char.isspace():
capitalize_next = True
return title_case_string
user_input = input("Enter a string with more than one word: ")
title_case_result = convert_to_title_case(user_input)
print("Original String:", user_input)
print("Title Case String:", title_case_result)
Output:
Enter a string with more than one word: I enjoy my computer classes at
BASE PU College
Original String: I enjoy my computer classes at BASE PU College
Title Case String: I Enjoy My Computer Classes At Base Pu College
18. Write a function that takes a sentence as an input
parameter, replaces each space with a hyphen, and returns 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)
Output:
Output:
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
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.")
Output:
Output:
email_ids_tuple = tuple(email_ids)
usernames_tuple = tuple(usernames)
domains_tuple = tuple(domains)
print("Email IDs Tuple:", email_ids_tuple)
print("Usernames Tuple:", usernames_tuple)
print("Domains Tuple:", domains_tuple)
Output:
name = tuple()
n = int(input("How many names do you want to enter? "))
for i in range(0, n):
num = input(">")
name = name + (num,)
print("\n The names entered in the Tuple are:")
print(name)
search = input("\n Enter the name of the student you want to search? ")
if search in name:
print("The name", search, "is present in the Tuple")
else:
print("The name", search, "is not found in the Tuple")
Output:
Output: