Kendriya Vidyalaya: NAME: Amogh R. Joshi Class: X TH A Roll No.: 25 SUBJECT: Artificial Intelligence
Kendriya Vidyalaya: NAME: Amogh R. Joshi Class: X TH A Roll No.: 25 SUBJECT: Artificial Intelligence
VIDYALAYA
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: ")
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
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: "))
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
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
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:
Output:
Enter the first number: 4
Enter the second number: 6
The LCM of 4 and 6 is 12