G-9 AI Practical Assessment (Python) 2023-24
G-9 AI Practical Assessment (Python) 2023-24
INTELLIGENCE
(PRACTICAL FILE)
SUBJECT CODE: 417
(Language: Python)
____________________________________
Salwan Public School
Sector-15(II), Gurugram-122001
TABLE OF CONTENT
S.NO
PROGRAM T. Sign
.
Write a program to ask the user to enter his first name and last name and print it
1.
on the screen.
Write a program to ask the user to enter a number and check if the number is odd
2.
or even.
Write a program to ask the user to enter three numbers and check which one is
3.
the greatest among the three.
Write a program to ask the user to enter three numbers and print the smallest
4.
number out of them.
Write a program to ask the user to enter his/her age and check whether he/she is
5.
eligible to drive or not.
Write a program to ask the user to enter his/her marks of 5 subjects and calculate
7.
the percentage and print it on the screen.
Write a program to ask the user to enter the temperature in Fahrenheit and
8.
convert it to Celsius.
Python Code:
```
Output
You can run this program in a Python environment, and it will prompt you to enter your first and last
names, then print the full name on the screen.
Program-2: Write a program to ask the user to enter a number and check if the number is odd or even.
Python Code
```python
If user_input % 2 == 0:
Else:
```
Output :
Copy and paste this code into a Python environment, and it will prompt you to enter a number and then
tell you whether it’s odd or even.
Program – 3 Write a program to ask the user to enter three numbers and check which one is the
greatest among the three.
Input:
```python
Else:
```
Output:
This program prompts the user to enter three numbers and then determines and prints the greatest
among them.
Program – 4 Write a program to ask the user to enter three numbers and print the smallest number out
of them.
Input:
```python
```
Output:
Copy and paste this code into a Python environment to run it.
Program – 5 Write a program to ask the user to enter his/her age and check whether he/she is eligible
to drive or not.
Input:
```python
Else:
```
Output:
Copy and paste this code into a Python environment to run it.
Input:
```python
def sum_of_natural_numbers(n):
sum_value = (n * (n + 1)) // 2
return sum_value
# Example usage:
n = int(input("Enter a positive integer (n): "))
result = sum_of_natural_numbers(n)
```
Output:
This program uses the formula for the sum of the first n natural numbers, which is `sum = n * (n + 1) /
2`
Program – 7 Write a program to ask the user to enter his/her marks of 5 subjects and calculate the
percentage and print it on the screen.
Input :
```python
```
Output:
Copy and paste this code into a Python environment, run it, and enter the marks for each subject when
prompted. The program will then calculate the total marks and percentage and display it on the screen.
Program – 8 Write a program to ask the user to enter the temperature in Fahrenheit and convert it to
Celsius.
Input:
```python
```
Output:
Copy and paste this code into a Python environment, and it will prompt you to enter the temperature in
Fahrenheit and then display the equivalent temperature in Celsius.
Program – 9 Write a python program to remove an empty element from the list :
Input:
```python
Print(num)
```
Output:
This program uses list comprehension and the `strip()` method to remove elements that are empty or
contain only whitespaces.
num=[18,19,20,21]
Input:
```python
Num.append(22)
Print(num)
Program – 11 Write a program to append data of the second list to the first list.
List1=[23,24,25,26] List2=[27,28,29,30]
Input:
```python
List1.extend(List2)
```
Output:
This program uses the `extend` method to append the elements of `List2` to the end of `List1`. The
final combined list is then printed.
Input:
```python
My_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Item_count = len(my_list)
```
Output:
This program uses the `len` function to get the length (number of items) in the list and then prints the
result.
Input :
```python
Original_list = [1, 2, 3, 4, 5]
Reversed_list = list(reversed(original_list))
```
Output:
For example:
Given x = [2, 3, 4, 5, 6]
```python
X = [2, 3, 4, 5, 6]
Print(“Original List:”, x)
```
Output:
This program uses a list comprehension to create a new list where each element is squared. The
original list and the squared list are then printed.
Program – 15 Write a program to ask the user to sort the given list:
List1=[40,50,33,23,12]
Input:
```python
If user_choice == ‘yes’:
List1.sort()
Else:
```
Output:
This program prompts the user to input whether they want to sort the list. If the input is ‘yes’, the list is
sorted using the `sort` method, and the sorted list is printed. If the input is 'no' or anything else, the
original list is printed as is.