0% found this document useful (0 votes)
2 views

Kush Python

This document is a practical file for the Fundamentals of Python Programming Lab for BCA II Semester students at Graphic Era Hill University. It includes a certification of completion for the lab experiments by the student Kushagra Sharma, along with a list of programming exercises covering various Python concepts. Each exercise includes objectives, sample code, and expected outputs.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Kush Python

This document is a practical file for the Fundamentals of Python Programming Lab for BCA II Semester students at Graphic Era Hill University. It includes a certification of completion for the lab experiments by the student Kushagra Sharma, along with a list of programming exercises covering various Python concepts. Each exercise includes objectives, sample code, and expected outputs.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Practical File

Fundamentals of Python
Programming Lab
(PBD 202)
BCA II Sem
Session 2024-27

Submitted to: Submitted by:


DR. JANMEJAY PANT KUSHAGRA SHARMA
Professor BCA(AI/DS)

School of Computing Section-B

Graphic Era Hill University Roll No-55

Bhimtal Campus
THIS IS TO CERTIFY THAT KUSHAGRA SHARMA HAS
SATISFACTORILY COMPLETED ALL THE EXPERIMENTS IN THE
LABORATORY OF THIS COLLEGE. THE COURSE OF THE TERM
WORK IN PARTIAL FULLMENT OF THE
REQUIREMENT IN SECOND SEMESTER OF BCA DEGREE COURSE
PRESCRIBED BY THE GRAPHIC ERA HILL UNIVERSITY BHIMTAL
DURING THE YEAR.

CONCERNED FACULTY HEAD OF DEPARTMENT

NAME OF EXAMINER:

SIGNATURE
Exp. No. Date Experiment Page No. Remarks

1 Write a program to get the marks of five


subjects from the user, calculate the
average marks, and find the grade.
2 Write a program to make a calculator and
perform basic arithmetic based on user
input. The menu should be continuously
available.
3 Write a program to take a number from the
user and check if it is smaller than 100. If
so, determine whether the number is even
or odd.
4 Write a program to take a character from
the user and check whether it is uppercase,
lowercase, digit, or a special character.
5 Write a program to find the largest of three
numbers.

6 Write a program to check whether the last


digit of a number is divisible by 5.

7 Write a program to create a list and print


the original list as well as twice of each
number.
8 Write a program to print the table of 5 and
terminate the loop when the value exceeds
10 using the break statement.
9 Write a program to print all prime
numbers within a given range.

10 Write a program to print the first n


numbers of the Fibonacci series.

11 Write a program to find the smallest and


largest number in a list.

12 Write a program to check whether a given


string is a palindrome or not.

13 Write a program to find the second highest


number in a list.

14 Write a program to reverse a list.

15 Write a program to convert a tuple into a


list and vice versa.

16 Write a program to concatenate two lists.

17 Write a program to count the occurrence


of a specified element in a tuple.
18 Write a program to check whether a given
year is a leap year or not.

19 Write a program to find the factorial of a


number.

20 Write a program to print even numbers


between 2 and n.

Program Objective:
Write a program to get the marks of five subjects from the user, calculate the average marks, and find
the grade.

Program:
marks = [] for i

in range(5):
marks.append(float(input(f"Enter marks for subject {i+1}: ")))

average = sum(marks) / 5 if 91 <= average <= 100:

grade = "A" elif 81 <=

average <= 90:

grade = "B" elif 71 <=

average <= 80:

grade = "C" elif 61 <=

average <= 70:

grade = "D" elif 51 <=

average <= 60:

grade = "E" else:

grade = "F" print(f"Average Marks:

{average:.2f}") print(f"Grade:

{grade}")

Output:
Program Objective:

Write a program to make a calculator and perform basic arithmetic based on user input. The menu
should be continuously available.

Program:
while True:

print("\nSimple Calculator")

print("1. Addition") print("2.

Subtraction") print("3.

Multiplication") print("4. Division")

print("5. Exit") choice = input("Enter

choice (1-5): ")

if choice == '5':

print("Exiting calculator.")

break

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

if choice == '1':

print(f"Result: {num1 + num2}")

elif choice == '2':

print(f"Result: {num1 - num2}")

elif choice == '3':

print(f"Result: {num1 * num2}")

elif choice == '4': if num2 == 0:

print("Error! Division by zero.")

else:

print(f"Result: {num1 / num2}")

else:

print("Invalid choice! Please try again.")

Output:
Write a program to take a number from the user and check if it is smaller than 100. If so, determine
whether the number is even or odd.

Program:
num = int(input("Enter a number: "))

if num < 100: if num % 2 == 0:

print("The number is even.")


Program Objective:

else: print("The number

is odd.") else:

print("The number is not smaller than 100.")

Output:
Program Objective:

Write a program to take a character from the user and check whether it is uppercase, lowercase,
digit, or a special character.

Program:
char = input("Enter a character: ") if

char.isupper():

print("The character is uppercase.") elif

char.islower():

print("The character is lowercase.") elif

char.isdigit():

print("The character is a digit.") else:

print("The character is a special character.")

Output:

Write a program to find the largest of three numbers.


Program Objective:

Program:
num1 = int(input("Enter first number: "))

num2 = int(input("Enter second number: "))

num3 = int(input("Enter third number: "))

largest = max(num1, num2, num3) print("The

largest number is:", largest)

Output:

Write a program to check whether the last digit of a number is divisible by 5.

Program:
Program Objective:

num = int(input("Enter a number: "))

last_digit = num % 10 if last_digit %

5 == 0:

print("The last digit is divisible by 5.") else:

print("The last digit is not divisible by 5.")

Output:
Program Objective:
Write a program to create a list and print the original list as well as twice of each number.

Program:
numbers = [2, 4, 6, 8, 10] print("Original list:",

numbers) doubled_numbers = [num * 2 for num in

numbers] print("Doubled list:", doubled_numbers)

Output:

Write a program to print the table of 5 and terminate the loop when the value exceeds 10 using the
break statement.
Program Objective:

Program:
num = 5

for i in range(1, 20):

result = num * i if

result > 10:

break

print(result)

Output:

Write a program to print all prime numbers within a given range.

Program:
def is_prime(n):

if n < 2:
Program Objective:

return False for i in range(2,

int(n ** 0.5) + 1): if n % i == 0:

return False

return True start = int(input("Enter start of range: ")) end = int(input("Enter end of

range: ")) print("Prime numbers in range:", [num for num in range(start, end + 1) if

is_prime(num)])

Output:

Write a program to print the first n numbers of the Fibonacci series.

Program:
n = int(input("Enter the number of Fibonacci terms: "))

fib = [0, 1] for i in

range(2, n):

fib.append(fib[-1] + fib[-2]) print("Fibonacci

series:", fib[:n])
Program Objective:

Output:

Write a program to find the smallest and largest number in a list.

Program:
numbers = [10, 5, 8, 20, 3] smallest

= min(numbers) largest =

max(numbers) print("Smallest

number:", smallest) print("Largest

number:", largest)

Output:
Program Objective:

Write a program to check whether a given string is a palindrome or not.

Program:
text = input("Enter a string: ") if

text == text[::-1]:

print("The string is a palindrome.")

else: print("The string is not a

palindrome.")

Output:
Program Objective:

Write a program to find the second highest number in a list.

Program:
numbers = [10, 20, 5, 8, 30]

numbers.sort(reverse=True)

second_highest = numbers[1]

print("Second highest number:",second_highest)

Output:
Program Objective:

Write a program to reverse a list.

Program:
numbers = [1, 2, 3, 4, 5]

reversed_list = numbers[::-1]

print("Reversed list:", reversed_list)

Output
Program Objective:

Write a program to convert a tuple into a list and vice versa.

Program:
my_tuple = (1, 2, 3, 4, 5)

my_list = list(my_tuple)

print("Tuple to List:", my_list)

new_tuple = tuple(my_list)

print("List to Tuple:", new_tuple)

Output:

Write a program to concatenate two lists.


Program Objective:

Program:
list1 = [1, 2, 3] list2 = [4, 5, 6]

concatenated_list = list1 + list2

print("Concatenated list:", concatenated_list)

Output:

Write a program to count the occurrence of a specified element in a tuple.

Program:
Program Objective:

my_tuple = (1, 2, 3, 4, 2, 5, 2, 6) element = int(input("Enter the

element to count: ")) count = my_tuple.count(element) print(f"The

element {element} appears {count} times in the tuple.")

Output:

Write a program to check whether a given year is a leap year or not.

Program:
year = int(input("Enter a year: ")) if (year % 4 == 0 and

year % 100 != 0) or (year % 400 == 0):


Program Objective:

print("It is a leap year.")

else: print("It is not a leap

year.")

Output:

Write a program to find the factorial of a number.

Program:
num = int(input("Enter a number: "))

factorial = 1 for i in

range(1, num + 1):


Program Objective:

factorial *= i print(f"Factorial of

{num} is {factorial}.")

Output:

Write a program to print even numbers between 2 and n.

Program:
n = int(input("Enter a number: ")) print("Even numbers:",

[num for num in range(2, n + 1, 2)])


Program Objective:

You might also like