Readable_Python_Code_with_Output
Readable_Python_Code_with_Output
print("Found:", found)
Input:
Output:
Found: True
smallest = min(nums)
largest = max(nums)
print("Smallest:", smallest)
print("Largest:", largest)
Input:
Output:
Smallest: 1
Largest: 8
students = {}
for _ in range(n):
students[name] = marks
# Find students scoring above 75
Input:
Number of students: 2
Name: Alice
Marks: 80
Name: Bob
Marks: 70
Output:
word_count = len(line.split())
Input:
Output:
Words: 3
result = ""
for i, c in enumerate(s):
if i % 2 == 0:
result += c.lower()
else:
result += c.upper()
print("Result:", result)
Input:
Result: hElLo
is_perfect = sum_of_divisors == n
print("Perfect:", is_perfect)
print("Palindrome:", is_palindrome)
Input:
Enter number: 28
Output:
Perfect: True
Palindrome: False
7. Armstrong number check
Code:
is_armstrong = n == armstrong_sum
print("Armstrong:", is_armstrong)
Input:
Output:
Armstrong: True
if n <= 1:
result = "Neither prime nor composite"
else:
print(result)
Input:
Enter number: 29
Output:
Prime
9. Fibonacci series
Code:
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
Input:
Enter terms: 5
Output:
01123
g = gcd(a, b)
lcm = a * b // g
print("GCD:", g)
print("LCM:", lcm)
Input:
Output:
GCD: 6
LCM: 36
# Initialize counters
for c in s:
if c.isalpha():
if c.lower() in "aeiou":
vowels += 1
else:
consonants += 1
if c.isupper():
uppercase += 1
if c.islower():
lowercase += 1
print("Vowels:", vowels)
print("Consonants:", consonants)
print("Uppercase:", uppercase)
print("Lowercase:", lowercase)
Input:
Output:
Vowels: 2
Consonants: 3
Uppercase: 1
Lowercase: 4
is_palindrome = s == s[::-1]
converted = s.swapcase()
print("Palindrome:", is_palindrome)
Output:
Palindrome: False
smallest = min(nums)
largest = max(nums)
print("Smallest:", smallest)
print("Largest:", largest)
Input:
Enter numbers: 7 2 9
Output:
Smallest: 2
Largest: 9
14. Swap elements at even and odd locations
Code:
print("Swapped:", nums)
Input:
Enter numbers: 1 2 3 4
Output:
Swapped: [2, 1, 4, 3]