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

Jenish Thapa

7t6

Uploaded by

abhiudayas.epost
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 views4 pages

Jenish Thapa

7t6

Uploaded by

abhiudayas.epost
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/ 4

20 Python Programs:

1. Check Positive/Negative/Zero

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

if num > 0:

print("Positive")

elif num < 0:

print("Negative")

else:

print("Zero")

2. Print Numbers 1 to 10

for i in range(1, 11):

print(i)

3. Sum of Numbers from 1 to 50

total, i = 0, 1

while i <= 50:

total += i

i += 1

print(total)

4. Prime Numbers from 1 to 100

for num in range(2, 101):

prime = True

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

if num % i == 0:

prime = False

break
if prime:

print(num)

5. Multiplication Table (2 to 5)

for i in range(2, 6):

for j in range(1, 11):

print(f"{i} x {j} = {i*j}")

6. Factorial Calculator

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

fact = 1

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

fact *= i

print(fact)

7. Even/Odd Checker

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

if num % 2 == 0:

print("Even")

else:

print("Odd")

8. Find Largest of Three Numbers

a, b, c = map(int, input("Enter three numbers: ").split())

largest = a if (a > b and a > c) else (b if b > c else c)

print("Largest:", largest)

9. Sum of Digits

num = input("Enter a number: ")

total = sum(int(digit) for digit in num)

print(total)

10. Reverse a String


text = input("Enter text: ")

print(text[::-1])

11. Check Palindrome

text = input("Enter text: ")

print("Palindrome" if text == text[::-1] else "Not a palindrome")

12. Fibonacci Sequence (10 terms)

a, b = 0, 1

for _ in range(10):

print(a)

a, b = b, a + b

13. Sum of Even Numbers from 1 to 100

print(sum(i for i in range(1, 101) if i % 2 == 0))

14. Count Vowels in a String

text = input("Enter text: ")

vowels = "aeiouAEIOU"

count = sum(1 for char in text if char in vowels)

print(count)

15. Generate Multiples of 3 up to 30

for i in range(3, 31, 3):

print(i)

16. Check Prime or Not

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

is_prime = all(num % i != 0 for i in range(2, int(num**0.5) + 1))

print("Prime" if is_prime else "Not prime")

17. Count Words in a Sentence

sentence = input("Enter a sentence: ")

words = sentence.split()
print("Number of words:", len(words))

18. Convert Celsius to Fahrenheit

celsius = float(input("Enter temperature in Celsius: "))

fahrenheit = (celsius * 9/5) + 32

print("Temperature in Fahrenheit:", fahrenheit)

19. Square of First 10 Natural Numbers

for i in range(1, 11):

print(i**2)

20. Number Guessing Game

import random

target = random.randint(1, 10)

guess = int(input("Guess (1-10): "))

print("Correct!" if guess == target else "Try again!")

You might also like