Docsity

AI python coding................., Study notes of Computer science

Toggle sidebar
bg1
DELHI PRIVATE SCHOOL โ€“ DUBAI GRADE 10 (2025-2026)
ARTIFICIAL INTELLIGENCE (SUBJECT CODE: 417)
ADVANCE PYTHON โ€“ PRACTICALS[Term1]
1. Write a Python program to print numbers from 1 to 20.
Code:
#Write a Python program to print numbers from 1 to 20
print("Generating numbers from 1 to 20")
for i in range(1,21):
print(i, end=" ")
Output:
Generating numbers from 1 to 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
2. Write a Python program to convert Temperature from Fahrenheit (โ„‰) to Celsius (โ„ƒ).
Code:
#To convert Temperature from Fahrenheit (โ„‰) to Celsius (โ„ƒ).
f = int(input("Enter the temperature in GFarehait:"))
c = (f-32)*5/9
print(f, "farenheit is = ",round(c,2),"Celsius")
Output:
Enter the temperature in GFarehait:40
40 farenheit is = 4.44 Celsius
3. Write a Python program to implement working of the traffic signal with appropriate
message.
Traffic Signal Display Message
RED STOP
GREEN GO
YELLOW READY
Any other entry INVALID ENTRY
Code:
#program to implement working of the traffic signal with appropriate
message.
sig= input("Enter the color(Red/Green/yellow):")
print("Traffic Signal Message display")
if sig == "Red":
print("Stop your Vehicle")
elif sig == "Green":
print("Move your Vehicle")
elif sig =="Yellow":
print("Slow Down your Vehicle")
else:
print("Invalid Color")
Output:
Enter the color(Red/Green/yellow):Yellow
Traffic Signal Message display
Slow Down your Vehicle
pf3
pf4
pf5

Partial preview of the text

Download AI python coding................. and more Study notes Computer science in PDF only on Docsity!

DELHI PRIVATE SCHOOL โ€“ DUBAI GRADE 10 (2025-2026)

ARTIFICIAL INTELLIGENCE (SUBJECT CODE: 417)

ADVANCE PYTHON โ€“ PRACTICALS[Term1]

1. Write a Python program to print numbers from 1 to 20.

Code:

#Write a Python program to print numbers from 1 to 20 print("Generating numbers from 1 to 20") for i in range( 1 , 21 ): print(i, end=" ")

Output:

Generating numbers from 1 to 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

2. Write a Python program to convert Temperature from Fahrenheit (โ„‰) to Celsius (โ„ƒ).

Code:

#To convert Temperature from Fahrenheit (โ„‰) to Celsius (โ„ƒ). f = int(input("Enter the temperature in GFarehait:")) c = (f- 32 )* 5 / 9 print(f, "farenheit is = ",round(c,2),"Celsius")

Output:

Enter the temperature in GFarehait: 40 farenheit is = 4.44 Celsius

3. Write a Python program to implement working of the traffic signal with appropriate

message.

Traffic Signal Display Message

RED STOP

GREEN GO

YELLOW READY

Any other entry INVALID ENTRY

Code:

#program to implement working of the traffic signal with appropriate message. sig= input("Enter the color(Red/Green/yellow):") print("Traffic Signal Message display") if sig == "Red": print("Stop your Vehicle") elif sig == "Green": print("Move your Vehicle") elif sig =="Yellow": print("Slow Down your Vehicle") else: print("Invalid Color")

Output:

Enter the color(Red/Green/yellow):Yellow Traffic Signal Message display Slow Down your Vehicle

4. Write a Python program to implement an ATM transaction with appropriate message.

Code:

program to implement an ATM transaction with appropriate message

b=float(input("Enter the balance:")) print("\n--- ATM Menu ---") print("1. Check Balance") print("2. Deposit") print("3. Withdraw") print("4. Exit") choice = input("Enter your choice (1-4): ") if choice == '1': print("Your balance is:", b) elif choice == '2': amount = float(input("Enter the amount to deposit: ")) b += amount print("Your new balance is:", b) elif choice == '3': amount = float(input("Enter the amount to withdraw: ")) if amount > b: print("Insufficient balance") else: b - = amount print("Your new balance is:", b) elif choice == '4': print("Thank you for using the ATM") else: print("Invalid choice")

Output:

Enter the balance: --- ATM Menu ---

  1. Check Balance
  2. Deposit
  3. Withdraw
  4. Exit Enter your choice (1-4): 2 Enter the amount to deposit: 5000 Your new balance is: 20000.

5. Write a Python program to calculate the average of three subjectsโ€™ marks.

Code:

#program to calculate the average of three subjectsโ€™ marks. a=int(input("enter the marks of English:")) b=int(input("enter the marks of Math:")) c=int(input("enter the marks of Science:")) avg=(a+b+c)/ 3 print("The average marks of three subjects is:",round(avg, 2 ))

Output:

enter the marks of English: enter the marks of Math: enter the marks of Science: The average marks of three subjects is: 90.

9. Write a Python program to create a list of 5 tourist places.

a) Accept list elements from the user.

b) Add list elements using append(), insert() and extend()

c) Display the list elements

d) Delete 2 nd^ element of the list using pop()

e) Delete 3 rd^ element of the list using remove()

Code:

#Program to create a list of 5 tourist places tp1=["Eiffel Tower","Burj Khalifa"] tp2=["Taj Mahal","Great Wall of China"] print("Tourist places List1 :",tp1) print("Tourist places List1 :",tp2) tp1.extend(tp2) print() print("The updated List is:",tp1) new_tp=input("Enter a new tourist place:") tp1.append(new_tp) print() print("The updated List using append is:",tp1) new_tp=input("Enter a new tourist place to insert in 3 position:") tp1.insert( 2 ,new_tp) print() print("The updated List using insert is:",tp1) tp1.pop( 1 ) print() print("The updated List after poping 2nd element is:",tp1) tp1.remove("Taj Mahal") print() print("The updated List after using remove is:",tp1)

Output:

Tourist places List1 : ['Eiffel Tower', 'Burj Khalifa'] Tourist places List1 : ['Taj Mahal', 'Great Wall of China'] The updated List is: ['Eiffel Tower', 'Burj Khalifa', 'Taj Mahal', 'Great Wall of China'] Enter a new tourist place:Bali The updated List using append is: ['Eiffel Tower', 'Burj Khalifa', 'Taj Mahal', 'Great Wall of China', 'Bali'] Enter a new tourist place to insert in 3 position:Petra The updated List using insert is: ['Eiffel Tower', 'Burj Khalifa', 'Petra', 'Taj Mahal', 'Great Wall of China', 'Bali'] The updated List after poping 2nd element is: ['Eiffel Tower', 'Petra', 'Taj Mahal', 'Great Wall of China', 'Bali'] The updated List after using remove is: ['Eiffel Tower', 'Petra', 'Great Wall of China', 'Bali']

10. Write a program to add the elements of the two lists.

Code:

#program to add the elements of the two lists. import numpy as np a=[ 10 , 20 , 30 , 40 ] b=[ 50 , 60 , 70 , 80 ] print("List1:",a) print("List2:",b) c=np.add(a,b) result=c.tolist() print("The updated List is:",result)

Output:

List1: [10, 20, 30, 40] List2: [50, 60, 70, 80] The updated List is: [60, 80, 100, 120]