ARTIFICIAL INTELLIGENCE
PRACTICAL FILE
Name: Kavya Sahay
Class: IX-F
Roll no: 20
Submitted To: Ms. Vishesha Sharma
INDEX
S.NO TOPIC
1 Age Calculator
Write a Python program that asks the user to enter their age.
● If the age is between 0 and 1, print "You are an infant."
● If the age is between 1 to 18, print “You are minor.”
● If the age is between 18 and 60 (inclusive), print "You are an adult."
● If the age is above 60, print "You are a senior citizen."
● If the user enters an invalid age, print “Invalid input”.
2 Traffic Signal Checker
Write a Python program that simulates a traffic light.
● Ask the user to enter the current light color ("red", "green", or "yellow").
● If the color is "red", print "Stop!"
● If the color is "green", print "Go!"
● If the color is "yellow", print "Slow Down!"
● If the user enters an invalid color, print "Invalid color."
● The program should be case insensitive i.e. the user can give input in any case.
3 Seasonal Fruit Checker
Write a Python program that works as season fruit checker
● Ask the user to enter the name of a fruit (e.g., "Mango", "Apple", "Grapes").
● Print the expected season for that fruit (e.g., "Summer", "Winter", "Autumn").
● If the fruit is not recognized, print "Fruit not recognized."
● Take any two fruits(of your choice) per season and use logical operators for the
conditions.
4 Number Classifcation
Write a Python program that asks the user to enter an integer.
Determine and print whether the number is:
● "Positive"
● "Negative"
● "Zero"
● "Even"
● "Odd"
Use nested if for optimization of code.
5 Library Book Fine Calculator
Write a Python program that calculates the fine for a library book based on the number
of days overdue.
● If the book is returned on time or within 5 days of the due date, the fine is 0.
● If the book is overdue by 6 to 10 days, the fine is Rs. 1 per day.
● If the book is overdue by more than 10 days, the fine is Rs. 2 per day.
● Ask the user to input the number of days the book is overdue.
Calculate and print the total fine.
Program 1: Age Calculator
Source Code :-
age=float(input("Your age="))
if age < 0:
print("Invalid input")
elif 0 <= age <= 1:
print("You are an infant.")
elif 1 < age < 18:
print("You are a minor.")
elif 18 <= age <= 60:
print("You are an adult.")
elif age > 60:
print("You are a senior citizen.")
else:
print("Invalid input")
Output :-
Program 2:
Source Code :-
clr = input("What colour is the Traffic Light (Red, Green, Yellow)=")
clr1= clr.lower()
if clr1 == "red":
print("Stop!")
elif clr1 == "yellow":
print("Slow Down!")
elif clr1 == "green":
print("Go!")
else:
print("Invalid Colour")
Output :-
Program 3:
Source Code :-
name= input("Name of the fruit (Watermelon, Mango, Pear, Apple, Grapefruit, Grapes)=")
name1= name.lower()
if name1== "watermelon" or name1=="mango":
print("Summer Fruit")
elif name1== "pear" or name1=="apple":
print("Winter Fruit")
elif name1=="grapefruit" or name1=="grapes":
print("Autumn Fruit")
Output :-
Program 4
Source Code :-
num = int(input("Write a number: "))
if num > 0 and num % 2 == 0 and num!=0:
print("Positive and Even Number")
elif num > 0 and num % 2 != 0:
print("Positive and Odd Number")
elif num < 0 and num % 2 != 0:
print("Negative and Odd Number")
elif num < 0 and num % 2 == 0 :
print("Negative and Even Number")
else:
print("Zero")
Output :-
Program 5
Source Code :-
days= int(input("No. of Days Issued:"))
if 0<=days<=5:
print("Rupees 0")
elif 6<=days<=10:
print("Rupees", days*1)
elif 10<days:
print("Rupees", days*2)
else:
print("Invalid input. Number of days cannot be negative.")
Output: