Kartik MLP 1-3
Kartik MLP 1-3
(P.I.E.T)
Department of
B. TECH CSE- AI &DS
Assessme
S. nt
Date of Practical
No. Name of Practical
Performance
Facult
Total Marks
File Record
Attendance
Viva (10)
y
Lab
(10)
(10)
(10)
(40)
Sign.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Total Marks
Aggregated Marks
Practical No. 1
Aim:
Write and run a python program that outputs the value of each of the following expression:
5.0/9.0,5.0/9,5/9.0,5/9,9.0/5.0,9.0/5,9/5.0,9/5
Based on your result, what is the rule for arithmetic operations when integers and floating point
numbers are used?
Objectives:
The objective of the code is to demonstrate how Python handles division involving both integers
and floating-point numbers, showing that the result is always a floating-point number regardless
of the types of operands.
Key Points:
1. Division with integers and/or floating-point numbers always results in a floating-point value.
2. Python automatically converts integers to floating-point numbers when necessary during
division.
3. The result of division (using /) is always a float, even if both operands are integers.
1. Source Code:
print(5.0/9.0)
print(5.0/9)
print(5/9.0)
print(5/9)
print(9.0/5.0)
print(9.0/5)
print(9/5.0)
print(9/5)
Output:
Rule:
When an arithmetic operation involves both integers and floating-point numbers (like division),
the result will always be a floating-point number. If all the operands are integers, Python will
perform integer division, but the result of division (using /) will always be a floating-point
number, even when dividing integers.
Practical No. 2
Aim: Write and run a python program that asks the user for a temperature in Celsius and converts
and outputs the temperature in Fahrenheit. (use the formula given in the example above and solve
for temp F in terms of temp C.)
Objective: The objective of this code is to convert a temperature provided in Celsius to Fahrenheit
using the formula F=C×95+32F = \frac{C \times 9}{5} + 32F=5C×9+32 and then output the result.
Key Points:
2. Converts Celsius to Fahrenheit using the formula F=C×95+32F = \frac{C \times 9}{5} +
32F=5C×9+32.
1. Source Code:
Output:
Practical No. 3
Aim: Here is an algorithm to print out n! (n factorial) from 0! to 19!
1. Self =1
2. Setn=0
a. Output n, “! =”, f
b. Add 1 to n
c. Multiply f by n
Using a for loop, write and run a Python for this algorithm.
3(a). Modify the program above using a while loop so it prints out all the factorial values that are
less than 1 billion.
3(b). Modify the first program so it finds the minimum in the array instead of the maximum.
3(c). (Harder) modify the first program so that it finds the index of the maximum in the array
rather than the maximum itself.
Objective: The objective of the code is to calculate and display factorial values, including:
Key Points:
2. Value Limitation: Outputs factorials less than 1 billion using a while loop.
3. Minimum Factorial: Finds and displays the minimum value in the factorial array.
4. Index of Maximum Factorial: Identifies the index of the maximum factorial in the array.
1. Source Code:
factorial = 1
Output:
3(a). Source Code: Using a while loop to print factorials less than 1 billion.
factorial = 1
n=0
Output:
3(b). Source Code: Finding the minimum factorial in an array of factorials from 0! to
19!
factorials = []
factorial = 1
min_factorial = min(factorials)
print(f"Minimum factorial: {min_factorial}")
Output:
3(c). Source Code: Finding the index of the maximum factorial in the array.
factorials = []
factorial = 1
max_factorial = max(factorials)
max_index = factorials.index(max_factorial)
print(f"Index of maximum factorial: {max_index}")
Output: