M1 -Pgm3838
M1 -Pgm3838
(7
1
Marks)
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
n = 5
. Write a Python program that takes a series of numbers from the user and calculates
2
their sum and average.
. Write a Python program to generate the following type of pattern for the given N rows.
3
(7 Marks)
1
1 2
1 2 3
1 2 3 4
. Write a Python code to determine whether the given string is a Palindrome or not using
4
slicing. Do not use any string function.
.Write a Python program to reverse a number and also find the sum of digits of the
5
number.
# Prompt user for input
number = int(input("Enter a number: "))
Initialize variables
#
reverse = 0
digit_sum = 0
6. Write a Python program to check whether the given number is an Armstrong or not.
Calculate the sum of digits raised to the power of the number of digits
#
for digit in num_str:
sum_of_powers += int(digit) ** num_digits
Initialize a variable to store the sum of digits raised to the power of num_digits
#
sum_of_powers = 0
If the square of sqrt_x1 or sqrt_x2 equals the original x1 or x2, the number is Fibonacci
#
if sqrt_x1 * sqrt_x1 == x1 or sqrt_x2 * sqrt_x2 == x2:
print(f"{number} is a Fibonacci number.")
else:
print(f"{number} is not a Fibonacci number.")
7.Write a Python code to check whether a given year is a leap year or not.
# Find the GCD of num1 and num2 using the Euclidean algorithm
while b != 0:
a, b = b, a % b
Now, calculate the LCM using the formula LCM(a, b) = abs(a * b) // GCD(a, b)
#
lcm = abs(num1 * num2) // a
2. Write a Python program to find X^Y or pow(X,Y) without using standard functions.
1
# Program to find X^Y without using standard functions
3.Write a Python program to enter a number from 1 to 7 and display the corresponding
1
day of the week using statements.
6. Write a Python program to count numbers between 1 to 100 not divisible by 2, 3 and
1
5.
Initialize counter
#
count = 0
6. Write a Python program to print all numbers between 100 and 1000 whose sum of the
1
digits are divisible by 9.
List of salaries
#
salaries = [2500.45, 3200.50, 4800.75, 1500.00, 2200.99]
Loop through the salaries list and print each number formatted with field width and precision
#
for salary in salaries:
print(f"{salary:>12.2f}")
9.Write a Python program to count the number of even numbers in a given set of n
1
numbers.
18. Write a Python program to evaluate the sequence: 1 + x + x2 + x3 + ⋯ + xn.
import math
# Program to find the sum of the cosine series 1 - x^2/2! + x^4/4! - ...
# Program to find the sum of the cosine series 1 - x^2/2! + x^4/4! - ...