prompt: Write a Python program to print 'Hello, World!'

code: print('Hello, World!')


prompt: Write a Python function to add two numbers.

code:
def add_numbers(a, b):
    return a + b


prompt: Write a Python function to subtract two numbers.

code:
def subtract_numbers(a, b):
    return a - b


prompt: Write a Python function to multiply two numbers.

code:
def multiply_numbers(a, b):
    return a * b


prompt: Write a Python function to divide two numbers.

code:
def divide_numbers(a, b):
    if b == 0:
        return 'Error: Division by zero'
    return a / b


prompt: Write a Python function to calculate the area of a rectangle.

code:
def rectangle_area(length, width):
    return length * width


prompt: Write a Python function to calculate the circumference of a circle.

code:
import math
def circle_circumference(radius):
    return 2 * math.pi * radius


prompt: Write a Python function to calculate the area of a circle.

code:
import math
def circle_area(radius):
    return math.pi * radius**2


prompt: Write a Python function to convert Celsius to Fahrenheit.

code:
def celsius_to_fahrenheit(celsius):
    return (celsius * 9/5) + 32


prompt: Write a Python function to convert Fahrenheit to Celsius.

code:
def fahrenheit_to_celsius(fahrenheit):
    return (fahrenheit - 32) * 5/9


prompt: Write a Python function to check if a number is even.

code:
def is_even(n):
    return n % 2 == 0


prompt: Write a Python function to check if a number is odd.

code:
def is_odd(n):
    return n % 2 != 0


prompt: Write a Python function to find the maximum of two numbers.

code:
def find_max(a, b):
    if a > b:
        return a
    else:
        return b


prompt: Write a Python function to find the minimum of two numbers.

code:
def find_min(a, b):
    if a < b:
        return a
    else:
        return b


prompt: Write a Python function to calculate the sum of numbers in a list.

code:
def sum_list(numbers):
    total = 0
    for num in numbers:
        total += num
    return total


prompt: Write a Python function to calculate the average of numbers in a list.

code:
def average_list(numbers):
    if not numbers:
        return 0
    return sum(numbers) / len(numbers)


prompt: Write a Python function to find the largest number in a list.

code:
def find_largest(numbers):
    if not numbers:
        return None
    largest = numbers[0]
    for num in numbers:
        if num > largest:
            largest = num
    return largest


prompt: Write a Python function to find the smallest number in a list.

code:
def find_smallest(numbers):
    if not numbers:
        return None
    smallest = numbers[0]
    for num in numbers:
        if num < smallest:
            smallest = num
    return smallest


prompt: Write a Python function to reverse a string.

code:
def reverse_string(s):
    return s[::-1]


prompt: Write a Python function to check if a string is a palindrome.

code:
def is_palindrome(s):
    return s == s[::-1]


prompt: Write a Python function to count the number of vowels in a string.

code:
def count_vowels(s):
    vowels = 'aeiouAEIOU'
    count = 0
    for char in s:
        if char in vowels:
            count += 1
    return count


prompt: Write a Python function to convert a string to uppercase.

code:
def to_uppercase(s):
    return s.upper()


prompt: Write a Python function to convert a string to lowercase.

code:
def to_lowercase(s):
    return s.lower()


prompt: Write a Python function to find the length of a string.

code:
def string_length(s):
    return len(s)


prompt: Write a Python function to check if a list is empty.

code:
def is_list_empty(lst):
    return len(lst) == 0


prompt: Write a Python function to append an element to a list.

code:
def append_to_list(lst, element):
    lst.append(element)
    return lst


prompt: Write a Python function to remove an element from a list.

code:
def remove_from_list(lst, element):
    if element in lst:
        lst.remove(element)
    return lst


prompt: Write a Python function to sort a list of numbers in ascending order.

code:
def sort_list_ascending(numbers):
    return sorted(numbers)


prompt: Write a Python function to sort a list of numbers in descending order.

code:
def sort_list_descending(numbers):
    return sorted(numbers, reverse=True)


prompt: Write a Python function to find the index of an element in a list.

code:
def find_index(lst, element):
    try:
        return lst.index(element)
    except ValueError:
        return -1


prompt: Write a Python function to check if an element exists in a list.

code:
def element_exists(lst, element):
    return element in lst


prompt: Write a Python function to get the first element of a list.

code:
def get_first_element(lst):
    if lst:
        return lst[0]
    else:
        return None


prompt: Write a Python function to get the last element of a list.

code:
def get_last_element(lst):
    if lst:
        return lst[-1]
    else:
        return None


prompt: Write a Python function to create a dictionary from two lists (keys and values).

code:
def create_dictionary(keys, values):
    return dict(zip(keys, values))


prompt: Write a Python function to get a value from a dictionary by its key.

code:
def get_dictionary_value(d, key):
    return d.get(key)


prompt: Write a Python function to add a new key-value pair to a dictionary.

code:
def add_to_dictionary(d, key, value):
    d[key] = value
    return d


prompt: Write a Python function to remove a key-value pair from a dictionary.

code:
def remove_from_dictionary(d, key):
    if key in d:
        del d[key]
    return d


prompt: Write a Python function to check if a key exists in a dictionary.

code:
def key_exists_in_dictionary(d, key):
    return key in d


prompt: Write a Python program to get user input and print it.

code:
user_input = input('Enter something: ')
print('You entered:', user_input)


prompt: Write a Python function to greet a user by name.

code:
def greet_user(name):
    return f'Hello, {name}!'


prompt: Write a Python function to calculate the square of a number.

code:
def square_number(n):
    return n * n


prompt: Write a Python function to calculate the cube of a number.

code:
def cube_number(n):
    return n ** 3


prompt: Write a Python function to check if a year is a leap year.

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


prompt: Write a Python function to count occurrences of a character in a string.

code:
def count_character(s, char):
    return s.count(char)


prompt: Write a Python function to find the absolute value of a number.

code:
def absolute_value(n):
    return abs(n)


prompt: Write a Python function to generate a sequence of numbers.

code:
def generate_sequence(start, end, step):
    return list(range(start, end, step))


prompt: Write a Python function to check if a list contains duplicates.

code:
def has_duplicates(lst):
    return len(lst) != len(set(lst))


prompt: Write a Python function to get the current date.

code:
from datetime import date
def get_current_date():
    return date.today()


prompt: Write a Python function to get the current time.

code:
from datetime import datetime
def get_current_time():
    return datetime.now().time()


prompt: Write a Python function to simulate a simple coin flip (Heads or Tails).

code:
import random
def coin_flip():
    return random.choice(['Heads', 'Tails'])