Python Program - Mca - 3 Sem
Python Program - Mca - 3 Sem
III SEMESTER
PYTHON PROGRAMMING LAB
Total Hours: 40 per batch
Hours/Week: 4
Max Marks: 100 Credits: 2
Choose any 15 Programs
PART A
1. Write a Python program to demonstrate basic data type in python
>>> x = 20 #int
>>> print(x)
20
>>> print(type(x))
<class 'int'>
>>> x = 20.5 #float
>>> print(x)
20.5
>>> print(type(x))
<class 'float'>
>>> x = 1j #complex
>>> print(x)
1j
>>> print(type(x))
<class 'complex'>
>>> x = "ACYTECH.COM" #String
>>> print(x)
ACYTECH.COM
>>> print(type(x))
<class 'str'>
>>> x = ["ACT", "TECH", "COMPANY"] #list
>>> print(x)
['ACT', 'TECH', 'COMPANY']
>>> print(type(x))
<class 'list'>
>>> x = ("ACT", "TECH", "COMPANY") #tuple
>>> print(x)
('ACT', 'TECH', 'COMPANY')
>>> print(type(x))
<class 'tuple'>
>>> x = {"name" : "anu", "age" : 36} #dict
>>> print(x)
{'name': 'anu', 'age': 36}
>>> print(type(x))
<class 'dict'>
>>> x = True #bool
>>> print(x)
True
>>> print(type(x))
<class 'bool'>
>>> x = b"Hello" #bytes
>>> print(x)
b'Hello'
>>> print(type(x))
<class 'bytes'>
>>> x = {"APPLE", "ORGANGE", "BANANA"} #set
>>> print(x)
{'ORGANGE', 'BANANA', 'APPLE'}
>>> print(type(x))
<class 'set'>
>>> x=frozenset({"APPLE", "ORGANGE", "BANANA"})#frozenset
>>> print(x)
frozenset({'ORGANGE', 'BANANA', 'APPLE'})
>>> print(type(x))
<class 'frozenset'>
Output:
Enter first number: 3
Enter second number: 2
The sum of 3 and 2 is 5.0
The subtraction of 3 and 2 is 1.0
The multiplication of 3 and 2 is 6.0
The division of 3 and 2 is 1.0
The division floor of 3 and 2 is 1
The Modulus of 3 and 2 is 1
The power of 3 and 2 is 6
Output:
Enter first side: 5.0
Enter second side: 6.0
Enter third side: 7.0
The area of the triangle is 14.70
else:
findRoots(a, b, c)
Output:
Enter a:7
Enter b:5
Enter c:2
Complex Roots
-0.35714285714285715 + i 5.5677643628300215
-0.35714285714285715 - i 5.5677643628300215
Output:
Please enter value for P: 25
Please enter value for Q: 03
The Value of P after swapping: 03
The Value of Q after swapping: 25
def kilometre_1(kmeter):
conversion_ratio_1= 0.621371
miles_1 = kmeter * conversion_ratio_1
print ("The speed value of car in Miles: ", miles_1)
kmeter = float (input ("Enter the speed of car in Kilometre as a unit: "))
kilometre_1(kmeter)
Output:
Enter the speed of car in Kilometre as a unit: 16
The speed value of car in Miles: 9.941936
Output:
April 2023
Mo Tu We Th Fr Sa Su
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Output:
Input a number : 150
It is positive number
Input a number : -150
It is negative number
Input a number : 0
It is Zero
Part- B
Output:
Enter a number: 15
15 is Odd
Output:
Enter year : 2023
2023 is not a leap year.
Output:
Enter an input number: 17
17 is a prime number
Output:
Enter the Lowest Range Value: 14
Enter the Upper Range Value: 60
The Prime Numbers in the range are:
17
19
23
29
31
37
41
43
47
53
59
15.Write a Python program to Find the Factorial of a Number
num = int(input("Enter a number: "))
factorial = 1
if num < 0:
print(" Factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
Output:
Enter a number: 10
The factorial of 10 is 3628800
num = int(input ("Enter the number of which the user wants to print the multipli
cation table: "))
for i in range(1, 11):
print(num, 'x', i, '=', num*i)
Output:
Enter the number of which the user wants to print the multiplication table: 12
12 x 1 = 12
12 x 2 = 24
12 x 3 = 36
12 x 4 = 48
12 x 5 = 60
12 x 6 = 72
12 x 7 = 84
12 x 8 = 96
12 x 9 = 108
12 x 10 = 120
17.Write a Python program to Print the Fibonacci sequence
n_terms = int(input ("Enter the limit "))
# First two terms
previous= 0
current = 1
count = 0
# Now, we will check if the number of terms is valid or not
if n_terms <= 0:
print ("Please enter a positive integer, the given number is not valid")
# if there is only one term, it will return n_1
elif n_terms == 1:
print ("The Fibonacci sequence of the numbers up to", n_terms, ": ")
print(previous)
# Then we will generate Fibonacci sequence of number
else:
print ("The fibonacci sequence of the numbers is:")
while count < n_terms:
print(previous)
new_ele = previous+ current
# At last, we will update values
previous = current
current = new_ele
count += 1
Output:
Enter the limit 7
The fibonacci sequence of the numbers is:
0
1
1
2
3
5
8
18.Write a Python program to Check Armstrong Number
number = int(input("Enter the number"))
Enter the number1245
digits = len(str(number))
temp = number
add_sum = 0
while temp != 0:
# get the last digit in the number
k = temp % 10
# find k^digits
add_sum += k**digits
# floor division
# which updates the number with the second last digit as the last digit
temp = temp//10
if add_sum == number:
print('Given number is an Armstrong Number')
else:
print('Given number is not a Armstrong Number')
Output:
Enter the number1245
Given number is not a Armstrong Number
Output:
Enter a number: 50
The sum is 1275