Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.4 kB
10
Indexable
Never
$$$$$$$$$$$$$$$   odd or even


def check_odd_even(number):
    if number % 2 == 0:
        return "Even"
    else:
        return "Odd"


user_input = int(input("Enter a number: "))


result = check_odd_even(user_input)
print(f"The number {user_input} is {result}.")


$$$$$$$$$$$$$$$  leap year 


def is_leap_year(year):
    
    if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
        return True
    else:
        return False


user_input = int(input("Enter a year: "))


if is_leap_year(user_input):
    print(f"The year {user_input} is a leap year.")
else:
    print(f"The year {user_input} is not a leap year.")


$$$$$$$$$$$$$$$ prime nnumber 


def is_prime(number):

    if number > 1:
        
        for i in range(2, int(number**0.5) + 1):
            if (number % i) == 0:
                return False  # It has a factor other than 1 and itself, so it's not prime
        return True
    else:
        return False  # Numbers less than or equal to 1 are not prime


user_input = int(input("Enter a number: "))


if is_prime(user_input):
    print(f"The number {user_input} is a prime number.")
else:
    print(f"The number {user_input} is not a prime number.")


$$$$$$$$$$$$$$$$$ code to fibonacci series 


def fibonacci_series(n):
    fib_series = [0, 1]  

    
    while len(fib_series) < n:
        next_term = fib_series[-1] + fib_series[-2]
        fib_series.append(next_term)

    return fib_series


num_terms = int(input("Enter the number of Fibonacci terms to generate: "))


result = fibonacci_series(num_terms)
print(f"Fibonacci series up to {num_terms} terms: {result}")



$$$$$$$$$$$$$$$$$ sum of n natural numbers


def sum_of_natural_numbers(n):
    return n * (n + 1) // 2

num_natural_numbers = int(input("Enter the value of n: "))

result = sum_of_natural_numbers(num_natural_numbers)
print(f"The sum of the first {num_natural_numbers} natural numbers is: {result}")



$$$$$$$$$$$$$$$$$ draw a pattern 

*
**
***



def draw_pattern(rows):
    for i in range(1, rows + 1):
        for j in range(i):
            print("*", end=" ")
        print()

num_rows = int(input("Enter the number of rows: "))
draw_pattern(num_rows)



$$$$$$$$$$$$ same for numbers 


def draw_pattern(rows):
    for i in range(1, rows + 1):
        for j in range(1, i + 1):
            print(j, end=" ")
        print()


num_rows = int(input("Enter the number of rows: "))


draw_pattern(num_rows)





Leave a Comment