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

Class IX Python Important Programs

The document contains ten Python programs that perform various tasks such as checking if a number is even or odd, finding the greater of two or three numbers, printing natural and even numbers, calculating sums, displaying multiplication tables, grading based on marks, and counting positive and negative numbers in a list. Each program includes user input and utilizes control structures like loops and conditionals. The programs are designed to demonstrate basic programming concepts and operations.

Uploaded by

Afraz Ali
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)
14 views2 pages

Class IX Python Important Programs

The document contains ten Python programs that perform various tasks such as checking if a number is even or odd, finding the greater of two or three numbers, printing natural and even numbers, calculating sums, displaying multiplication tables, grading based on marks, and counting positive and negative numbers in a list. Each program includes user input and utilizes control structures like loops and conditionals. The programs are designed to demonstrate basic programming concepts and operations.

Uploaded by

Afraz Ali
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

Program 1: To input a number from the user and check whether it is Even or Odd

num = int(input("Enter a number: "))

if num % 2 == 0:
print("Even")
else:
print("Odd")

Program 2: To input two numbers and display the greater of the two
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

if a > b:
print(a, "is greater")
else:
print(b, "is greater")

Program 3: To input three numbers and find the greatest among them
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

if a >= b and a >= c:


print(a, "is greatest")
elif b >= a and b >= c:
print(b, "is greatest")
else:
print(c, "is greatest")

Program 4: To print all natural numbers from 1 to n using a for loop


n = int(input("Enter value of n: "))

for i in range(1, n + 1):


print(i)

Program 5: To print all even numbers between 1 and n


n = int(input("Enter value of n: "))

for i in range(1, n + 1):


if i % 2 == 0:
print(i)

Program 6: To calculate and display the sum of first n natural numbers


n = int(input("Enter value of n: "))
sum = 0

for i in range(1, n + 1):


sum = sum + i

print("Sum =", sum)


2

Program 7: To display the multiplication table of a given number


num = int(input("Enter a number: "))

for i in range(1, 11):


print(num, "x", i, "=", num * i)

Program 8: To input marks and display the corresponding grade


marks = int(input("Enter marks: "))

if marks >= 90:


print("Grade A")
elif marks >= 75:
print("Grade B")
elif marks >= 50:
print("Grade C")
else:
print("Fail")

Program 9: To input elements into a list and display all the elements of the list
n = int(input("Enter number of elements: "))
lst = []

for i in range(n):
value = int(input("Enter element: "))
[Link](value)

for item in lst:


print(item)

Program 10: To count and display the number of positive and negative elements in a list
n = int(input("Enter number of elements: "))
lst = []

for i in range(n):
value = int(input("Enter element: "))
[Link](value)

positive = 0
negative = 0

for num in lst:


if num > 0:
positive += 1
elif num < 0:
negative += 1

print("Positive numbers:", positive)


print("Negative numbers:", negative)

You might also like