0% found this document useful (0 votes)
5 views2 pages

Class IX AI Practical File Python Codes

The document contains practical file codes for Class IX in Artificial Intelligence, focusing on if statements and loops. It includes various programs such as checking if a number is odd or even, determining if a number is positive or negative, and printing patterns. Each program is accompanied by its aim and input/output instructions.

Uploaded by

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

Class IX AI Practical File Python Codes

The document contains practical file codes for Class IX in Artificial Intelligence, focusing on if statements and loops. It includes various programs such as checking if a number is odd or even, determining if a number is positive or negative, and printing patterns. Each program is accompanied by its aim and input/output instructions.

Uploaded by

adviktehlan1121
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practical File Codes

Class IX – Artificial Intelligence

I) if Statement Programs
1) Odd or Even Number
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even number") Aim: to check whether a number is odd or even
else:
print("Odd number")

2) Positive or Negative Number


num = int(input("Enter a number: "))
if num >= 0: Aim: to Check whether a number is negative or positive
print("Positive number")
else:
print("Negative number")

3) Vowel or Consonant
ch = input("Enter a letter: ") Aim: to check whether a letter is vowel or consonant
if ch in 'aeiouAEIOU':
print("Vowel")
else:
print("Consonant")

4) Day of the Week


day = int(input("Enter week number (1-7): "))
if day == 1:
print("Sunday")
elif day == 2:
print("Monday")
elif day == 3:
print("Tuesday")
elif day == 4: Aim: to check what day comes first
print("Wednesday")
elif day == 5:
print("Thursday")
elif day == 6:
print("Friday")
elif day == 7:
print("Saturday")
else:
print("Invalid input")

5) Greater of Two Numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if a > b: Aim:to check whether a number is greater than two
print("First number is greater")
else:
print("Second number is greater")

II) for Loop and while Loop Programs


1) Print first 10 odd numbers
for i in range(1, 20, 2): Aim: to check what are the first 10 odd numbers
print(i)

2) Print name given number of times


name = input("Enter your name: ")
n = int(input("Enter number of times: ")) Aim:to check how many same names are given
for i in range(n):
print(name)

3) Print even numbers less than a given number

Aim:to check how many even numbers are there after a number
n = int(input("Enter a number: "))
for i in range(2, n, 2):
print(i)

4) Print first 10 natural numbers in reverse


for i in range(10, 0, -1):
print(i) Aim: to see first 10 natural numbers
5) Print pattern
for i in range(1, 5): Aim:to write a python programme to see a star pattern using for loop
print("*" * i)

FROM: Advik tehlan

9-B

You might also like