Professional Documents
Culture Documents
Ans :-
def display_welcome_message():
display_welcome_message()
Q.2 Inpul two numbers and display the larger/ smaller number?
Ans –
def compare_numbers():
# Input two numbers
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
3. def pattern_3():
for i in range(65, 70):
for j in range(65, i + 1):
print(chr(j), end="")
print()
def is_armstrong_number(number):
# Check if the number is an Armstrong number
num_digits = len(str(number))
digit_sum = sum(int(digit) ** num_digits for digit in str(number))
return digit_sum == number
def is_palindrome(number):
# Check if the number is a palindrome
return str(number) == str(number)[::-1]
def main():
# Input a number
number = int(input("Enter a number: "))
if is_armstrong_number(number):
print(f"{number} is an Armstrong number.")
else:
print(f"{number} is not an Armstrong number.")
if is_palindrome(number):
print(f"{number} is a palindrome.")
else:
print(f"{number} is not a palindrome.")
Ans :-
def is_prime(number):
if number < 2:
return False
if number % i == 0:
return False
return True
def main():
# Input a number
if is_prime(number):
else:
main()
return fib_series
def main():
# Input the number of terms for the Fibonacci series
n = int(input("Enter the number of terms for the Fibonacci series: "))
Ans :-
while y:
x, y = y, x % y
return abs(x)
# Compute the LCM of two numbers using the formula: LCM(x, y) = |x * y| / GCD(x, y)
def main():
main()
Ans :-
def count_characters(input_string):
# Initialize counters
vowels_count = 0
consonants_count = 0
uppercase_count = 0
lowercase_count = 0
# Define vowels
vowels = "AEIOUaeiou"
if char in vowels:
vowels_count += 1
elif char.isalpha():
consonants_count += 1
elif char.isupper():
uppercase_count += 1
elif char.islower():
lowercase_count += 1
def main():
# Input a string
count_characters(input_string)
main()
def convert_case(input_string):
# Convert the case of characters in the string
return input_string.swapcase()
def main():
# Input a string
input_string = input("Enter a string: ")
Ans :-
Finding the Largest Number in a List or Tuple:
def find_largest(numbers):
# Find the largest number in the list or tuple
largest_number = max(numbers)
return largest_number
Q.12 input a list of numbers and swap elemenis at ilhe even locatlun with the
elemenis at the odd location.
Ans:-
def swap_elements_at_odd_even_locations(input_list):
# Check if the list has even length, if not, ignore the last element
if len(input_list) % 2 == 1:
input_list = input_list[:-1]
return input_list
def main():
# Input a list of numbers
input_numbers = [int(x) for x in input("Enter a list of numbers separated by spaces:
").split()]
# Swap elements at even and odd locations and display the result
swapped_list = swap_elements_at_odd_even_locations(input_numbers)
print(f"The list after swapping elements at even and odd locations: {swapped_list}")
def main():
# Input a list or tuple of elements
input_container = eval(input("Enter a list or tuple of elements (e.g., [1, 2, 3]): "))
def main():
# Input the number of students
n = int(input("Enter the number of students: "))