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

Part A: Input Two Larger and Smaller Numbers

Uploaded by

vexsper
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

Part A: Input Two Larger and Smaller Numbers

Uploaded by

vexsper
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
You are on page 1/ 2

Here are shorter versions of the required codes:

Part A

1. Input two larger and smaller numbers

num1, num2 = int(input()), int(input())


print(f"Larger: {max(num1, num2)}, Smaller: {min(num1, num2)}")

2. Pattern:

print("*\n|\nO\n***")

3. Sum of the series (1 + x + x² + … + xⁿ)

x, n = int(input()), int(input())
print(sum(x**i for i in range(n+1)))

4. Find perfect number

n = int(input())
print(f"{n} is", "perfect" if sum(i for i in range(1, n) if n % i == 0) ==
n else "not perfect")

5. Find prime number

n = int(input())
print(f"{n} is", "prime" if n > 1 and all(n % i for i in range(2,
int(n**0.5)+1)) else "not prime")

6. Count vowels, consonants, uppercase, lowercase

s = input()
v, c, u, l = "aeiouAEIOU", 0, 0, 0
for i in s:
if i.isalpha(): c += i not in v; u += i.isupper(); l += i.islower()
print(f"Vowels: {sum(i in v for i in s)}, Consonants: {c}, Upper: {u},
Lower: {l}")

Part B

1. Input three numbers and display the largest/smallest


nums = [int(input()) for _ in range(3)]
print(f"Largest: {max(nums)}, Smallest: {min(nums)}")

2. Pattern:

n = 4
for i in range(n, 0, -1): print("".join(str(j) for j in range(1, i+1)))

3. Sum of the series (1 - x + x² - x³ + …)

x, n = int(input()), int(input())
print(sum((-x)**i for i in range(n+1)))

4. Find Armstrong number

n = int(input())
print(f"{n} is", "Armstrong" if n == sum(int(i)**len(str(n)) for i in
str(n)) else "not Armstrong")

5. Fibonacci series

n = int(input())
a, b = 0, 1
for _ in range(n): print(a, end=" "); a, b = b, a + b

6. Count vowels, consonants, uppercase, lowercase

s = input()
v, c, u, l = "aeiouAEIOU", 0, 0, 0
for i in s:
if i.isalpha(): c += i not in v; u += i.isupper(); l += i.islower()
print(f"Vowels: {sum(i in v for i in s)}, Consonants: {c}, Upper: {u},
Lower: {l}")

These are concise versions of the original codes!

You might also like