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

Python Basics: Even/Odd, Greatest, Sum, Vowels, Reverse

The document contains five Python code snippets that perform different tasks. The first checks if a number is even or odd, the second finds the greatest of three numbers, the third calculates the sum of numbers up to a given number, the fourth counts the number of vowels in a string, and the fifth reverses a given number. Each snippet prompts the user for input and displays the result.

Uploaded by

bosetaraknath02
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)
17 views2 pages

Python Basics: Even/Odd, Greatest, Sum, Vowels, Reverse

The document contains five Python code snippets that perform different tasks. The first checks if a number is even or odd, the second finds the greatest of three numbers, the third calculates the sum of numbers up to a given number, the fourth counts the number of vowels in a string, and the fifth reverses a given number. Each snippet prompts the user for input and displays the result.

Uploaded by

bosetaraknath02
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

1.

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


if num % 2 == 0:
print(num, "is Even")
else:
print(num, "is Odd")
2.
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")
3.
n = int(input("Enter a number: "))
s=0
for i in range(1, n + 1):
s += i
print("Sum =", s)
4.
text = input("Enter a string: ")
vowels = "aeiouAEIOU"
count = 0
for ch in text:
if ch in vowels:
count += 1
print("Number of vowels =", count)
5.
num = int(input("Enter a number: "))
rev = 0
while num > 0:
digit = num % 10
rev = rev * 10 + digit
num //= 10
print("Reversed number =", rev)

You might also like