python question for practice
1. Write the a program check leap year or not using python.
def is_leap_year(year):
if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0):
return True
return False
year = 2024
if is_leap_year(year):
print(f"{year} is a leap year.")
else:
print(f"{year} is not a leap year.")
Output: 2024 is a leap year
2. Write the a program find factorial using python .
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
num = 5
print(f"The factorial of {num} is {factorial(num)}.")
Output: The factorial of 5 is 120 .
3. write the a program find the prime number using python.
def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
num = 17
if is_prime(num):
print(f"{num} is a prime number.")
else:
print(f"{num} is not a prime number.")
Output: 17 is prime number.
python question for practice
Reviewed by For Learnig
on
August 11, 2024
Rating:
No comments:
If you have any doubts, please tell me know