0% found this document useful (0 votes)
7 views7 pages

Grade 9 List of Python Programs

The document contains a list of 15 Python programs, each demonstrating different programming concepts such as calculating factorials, checking for prime and Armstrong numbers, finding the greatest of three numbers, and converting Celsius to Fahrenheit. Each program includes user input and relevant logic to perform the specified task. The document serves as a practical guide for beginners to learn Python programming through examples.

Uploaded by

realarnav156
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)
7 views7 pages

Grade 9 List of Python Programs

The document contains a list of 15 Python programs, each demonstrating different programming concepts such as calculating factorials, checking for prime and Armstrong numbers, finding the greatest of three numbers, and converting Celsius to Fahrenheit. Each program includes user input and relevant logic to perform the specified task. The document serves as a practical guide for beginners to learn Python programming through examples.

Uploaded by

realarnav156
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/ 7

LIST OF PYTHON PROGRAMS

1. Write a python program to find Factorial of a number

# Factorial program

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

factorial = 1

if num < 0:

print("Factorial does not exist for negative numbers")

elif num == 0:

print("The factorial of 0 is 1")

else:

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

factorial *= i

print("The factorial of num is”, factorial)

2. Write a python program to Check prime number

# Prime number check

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

if num <= 1:

print(f"{num} is not a prime number")

else:

is_prime = True

for i in range(2, int(num ** 0.5) + 1):

if num % i == 0:

is_prime = False

break
if is_prime:

print(num, “is a prime number")

else:

print(num, “is not a prime number")

3. Write a python program to find the greatest of three numbers

# Greatest of three numbers

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

b = int(input("Enter second number: "))

c = int(input("Enter third number: "))

if a >= b and a >= c:

greatest = a

elif b >= a and b >= c:

greatest = b

else:

greatest = c

print(“The greatest number is”, greatest)

4. Write a python program to check for Armstrong number

# Armstrong number check

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

sum_of_powers = 0

digits = len(str(num))

temp = num

while temp > 0:


digit = temp % 10

sum_of_powers += digit ** digits

temp //= 10

if num == sum_of_powers:

print(num, “is an Armstrong number")

else:

print(num, “ is not an Armstrong number")

5. Write a python program to Calculate simple interest with principal, rate & time
entered by the user

# Simple Interest

p = float(input("Enter Principal amount: "))

r = float(input("Enter Rate of Interest: "))

t = float(input("Enter Time (in years): "))

SI = (p * r * t) / 100

print(“Simple Interest =” SI)

6. Write a python program to Check palindrome number

# Palindrome check using while loop

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

temp = num

rev = 0

while temp > 0:

digit = temp % 10

rev = (rev * 10) + digit

temp //= 10
if num == rev:

print(num, “is a Palindrome number")

else:

print(num, “is not a Palindrome number")

7. Write a python program to Sum of digits of a number

# Sum of digits

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

total = 0

temp = num

while temp > 0:

digit = temp % 10

total += digit

temp //= 10

print("Sum of digits of num is”, total)

8. Write a python program to find Factorial of a number

# Factorial

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

fact = 1

if num < 0:

print("Factorial not possible for negative numbers")

else:

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

fact *= i

print("Factorial of num is”, fact)


9. Write a python program to print Fibonacci series up to n terms

# Fibonacci series

n = int(input("Enter number of terms: "))

a, b = 0, 1

print("Fibonacci series:", end=" ")

for i in range(n):

print(a, end=" ")

a, b = b, a + b

10. Write a python program to sum up first 50 even numbers.

# Sum of first 50 even numbers

sum_even = 0

for i in range(1, 51): # first 50 even numbers

sum_even += 2 * i # even numbers are 2, 4, 6, ...

print("Sum of first 50 even numbers =", sum_even)

11. Write a python program to check Armstrong number (Eg. 153=1^3+2^3”3^3=153)

# Armstrong Number

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

order = len(str(num))

sum_of_powers = 0

temp = num

while temp > 0:

digit = temp % 10

sum_of_powers += digit ** order

temp //= 10
if num == sum_of_powers:

print(num, “is an Armstrong number")

else:

print(num, “is not an Armstrong number")

12. Write a python program to GCD of two numbers


# GCD of two numbers using while loop

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


b = int(input("Enter second number: "))

while b != 0:
a, b = b, a % b # keep reducing until remainder is 0

print("GCD =” , a)

13. Write a python program to convert Celsius to Fahrenheit F=5/9(C+32)


# Celsius to Fahrenheit
c = float(input("Enter temperature in Celsius: "))
f = (c * 9/5) + 32
print(c, “°C =” , f, “°F")

14. Write a python program to check if a number is perfect number


# Check Perfect Number

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


sum_divisors = 0

for i in range(1, num):


if num % i == 0:
sum_divisors += i

if sum_divisors == num:
print(f"{num} is a Perfect Number")
else:
print(f"{num} is not a Perfect Number")

15. Write a python program to print a right angled triangle with ‘*’

*
**
***
****
*****
# Right angled triangle

rows = int(input("Enter number of rows: "))

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

print("*" * i)

You might also like