0% found this document useful (0 votes)
25 views14 pages

Kendriya Vidyalaya: NAME: Amogh R. Joshi Class: X TH A Roll No.: 25 SUBJECT: Artificial Intelligence

Uploaded by

mundeasmita1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views14 pages

Kendriya Vidyalaya: NAME: Amogh R. Joshi Class: X TH A Roll No.: 25 SUBJECT: Artificial Intelligence

Uploaded by

mundeasmita1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

KENDRIYA

VIDYALAYA

NAME: Amogh R. Joshi


CLASS : X th A
ROLL NO. : 25
SUBJECT : Artificial Intelligence
CLASS Xth Artificial Intelligence
Practical

1) Input first name last name from user


and display full name

Algorithm:
Start
Take input for the first name from the user
Take input for the last name from the user
Concatenate the first name and last name with a space in
between
Display the full name
End
Python Source Code:
# Taking input from the user
first_name = input("Enter your first name: ")
last_name = input("Enter your last name: ")

# Concatenating first name and last name


full_name = first_name + " " + last_name

# Displaying the full name


print("Your full name is:", full_name)

Example Output:
Enter your first name: John
Enter your last name: Doe
Your full name is: John Doe
2. Input length and breadth of a rectangle and
calculate Area and Perimeter
Algorithm:
1. Start
2. Take input for the length of the rectangle
3. Take input for the breadth of the rectangle
4. Calculate the area using the formula: Area = length × breadth
5. Calculate the perimeter using the formula: Perimeter = 2 × (length +
breadth)
6. Display the area and perimeter
7. End

Source Code:
# Taking input from the user
length = float(input("Enter the length of the rectangle: "))
breadth = float(input("Enter the breadth of the rectangle: "))
# Calculating area and perimeter
area = length * breadth
perimeter = 2 * (length + breadth)
# Displaying the results
print("Area of the rectangle:", area)
print("Perimeter of the rectangle:", perimeter)

Example Output:
Enter the length of the rectangle: 5
Enter the breadth of the rectangle: 3
Area of the rectangle: 15.0
Perimeter of the rectangle: 16.0

3. To input the percentage of a student and


award "Certificate of Excellence" if the student
gets more than 80%.
Algorithm:
1. Start
2. Take input for the percentage of the student
3. Check if the percentage is greater than 80%
o If yes, print "Certificate of Excellence awarded"
o If no, print "Better luck next time!"
4. End
Source Code:
# Taking input from the user

percentage = float(input("Enter your percentage: "))


# Checking the condition
if percentage > 80:
print("Congratulations! You are awarded the 'Certificate of
Excellence'.")
else:
print("Better luck next time!")
Example Outputs:
Enter your percentage: 85
Congratulations! You are awarded the 'Certificate of Excellence'.
4. To put day of the week and in case it is
SUNDAY then extra cookie as a reward point
to be given with the order.
Algorithm:
1. Start
2. Take input for the day of the week
3. Convert the input to uppercase/lowercase to ensure case insensitivity
4. Check if the day is "Sunday"
o If yes, print "You get an extra cookie as a reward!"
o If no, print "No extra cookie today!"
5. End

Python Source Code:


# Taking input from the user
day = input("Enter the day of the week: ").strip().lower()
# Checking the condition
if day == "sunday":
print("You get an extra cookie as a reward!")
else:
print("No extra cookie today!")

Outputs:
Enter the day of the week: Sunday
You get an extra cookie as a reward!
5. To input two numbers and display the
bigger of the two numbers
Algorithm:
1. Start
2. Take input for the first number
3. Take input for the second number
4. Compare both numbers
o If the first number is greater, display it
o If the second number is greater, display it
o If both numbers are equal, print a message stating they are equal
5. End

Source Code:
# Taking input from the user
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# Checking which number is bigger
if num1 > num2:
print("The bigger number is:", num1)
elif num2 > num1:
print("The bigger number is:", num2)
else:
print("Both numbers are equal.")

Outputs:
Enter the first number: 10
Enter the second number: 25
The bigger number is: 25
6. To input a number and display
whether it is even or odd.

Algorithm:
1.Start
2. Take input for the number
3. Check if the number is divisible by 2
 If yes, print "The number is Even"
 If no, print "The number is Odd"
6. End
Source Code:
# Taking input from the user
num = int(input("Enter a number: "))

# Checking if the number is even or odd


if num % 2 == 0:
print("The number is Even.")
else:
print("The number is Odd.")

Outputs:
Enter a number: 8
The number is Even.
7.To input a number and check whether
the number is positive of negative.

Algorithm:
1. Start
2. Take input for the number
3. Check if the number is greater than 0 (positive):
 If yes, print "The number is positive"
4. Else, check if the number is less than 0 (negative):
 If yes, print "The number is negative"
5. If the number is 0, print "The number is zero"
6. End

Source Code:
# Taking input from the user
num = float(input("Enter a number: "))
# Checking if the number is positive, negative, or zero
if num > 0:
print("The number is positive.")
elif num < 0:
print("The number is negative.")
else:
print("The number is zero.")

Outputs:
Enter a number: 5
The number is positive.
7.To input billing amount and gender. If the
billing amount is more than 10000 and
gender is female, then discount is 15%
otherwise discount is 10%. Calculate the
billing amount accordingly.

Algorithm:
1. Start
2. Take input for the billing amount
3. Take input for the gender (ensure case insensitivity by converting to
lowercase or uppercase)
4. Check if the billing amount is more than 10000 and gender is female:
o If yes, apply a 15% discount
o If no, apply a 10% discount
5. Calculate the discount amount and the final billing amount
6. Display the final billing amount after the discount
7. End
Source Code:
# Taking input from the user
billing_amount = float(input("Enter the billing amount: "))
gender = input("Enter the gender (male/female):
").strip().lower()
if billing_amount > 10000 and gender == "female":
discount = 0.15 # 15% discount
else:
discount = 0.10 # 10% discount
discount_amount = billing_amount * discount
final_amount = billing_amount - discount_amount
print(f"Discount: {discount*100}%")
print(f"Final billing amount: {final_amount}")
Outputs:
Enter the billing amount: 15000
Enter the gender (male/female): female
Discount: 15.0%
Final billing amount: 12750.0

8.To input a number and check whether it is


multiple of 5 or not. This check is valid only for
positive numbers.
Algorithm:
1. Start
2. Take input for the number
3. Check if the number is positive
 If yes, check if the number is divisible by 5
o If yes, print "The number is a multiple of 5"
o If no, print "The number is not a multiple of 5"
 If the number is not positive, print "Please enter a positive number"
4.End

Source Code:
num = int(input("Enter a number: "))
if num > 0:
if num % 5 == 0:
print("The number is a multiple of 5.")
else:
print("The number is not a multiple of 5.")
else:
print("Please enter a positive number.")

Outputs:
Enter a number: 25
The number is a multiple of 5.
9.Write a program to input a string and
display the count of vowels and consonants
in the string.
Program:
# Taking input from the user
string = input("Enter a string: ").lower() # Converting to
lowercase for easy comparison
# Initializing counters
vowel_count = 0
consonant_count = 0
# Looping through each character in the string
for char in string:
if char.isalpha(): # Checking if the character is an alphabet
if char in 'aeiou': # Checking if the character is a vowel
vowel_count += 1
else:
consonant_count += 1
# Displaying the results
print(f"Vowels: {vowel_count}")
print(f"Consonants: {consonant_count}")

Output:
Please enter a string as you wish: Orange Education
The number of vowels: 8
The number of consonants: 8
10. Write a program to input a string and
display the string in the reverse order.

Program:
def reverse_string(str):
strl for i in str: strl i + strl return strl
str "Artificial Intelligence"
print("The original string is: ",str)
print("The reverse string is", reverse_string(str))

Output:
The original string is: ArtificialIntelligence
The reverse string is ecnegilletnllaicifitrA

11. Write a Python code to take the input of


a number n and then find and display its
factorial (nl), For example, 5! 5x4x3x2x1 i.e.,
120.
Program:
N= int (input("Enter a number: "))
factorial =1
if n < 0: print ("Factorial does not exist for negative numbers")
elif n 0: print ("The factorial of 0 is 1")
else: for i in range (1,n+1): factorial factorial i
print ("The factorial of ",n," is", factorial)
12. Write a Python code to input the lengths
of the three sides of a triangle and display
whether a triangle can be formed with the
inputs or not. If a triangle can be formed
then display whether the triangle will be
scalene isosceles or equilateral triangle.
Program:
print ("Input the sides of the triangle: ")
A = int (input("A: "))
B = int (input("B: "))
C = int (input("C: ")) BC:
if A ==B==c:
print("Equilateral triangle")
elif
A==B or B==C or A==C:
print("isosceles triangle")
else:
print("Scalene triangle")

Output:
Input the sides of the triangle:
A: 10
B: 10
C: 10
Equilateral triangle
13. . Write a program to input two numbers
and display the LCM of the two numbers.

Program:

# Taking input from the user


num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
# Finding the greater of the two numbers
greater = max(num1, num2)
# Loop to find the LCM
while True:
if greater % num1 == 0 and greater % num2 == 0:
lcm = greater
break
greater += 1
# Displaying the LCM
Print0020(f"The LCM of {num1} and {num2} is {lcm}")

Output:
Enter the first number: 4
Enter the second number: 6
The LCM of 4 and 6 is 12

You might also like