File size: 8,059 Bytes
6e793bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{"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):\n    return a + b"}
{"prompt": "Write a Python function to subtract two numbers.", "code": "def subtract_numbers(a, b):\n    return a - b"}
{"prompt": "Write a Python function to multiply two numbers.", "code": "def multiply_numbers(a, b):\n    return a * b"}
{"prompt": "Write a Python function to divide two numbers.", "code": "def divide_numbers(a, b):\n    if b == 0:\n        return 'Error: Division by zero'\n    return a / b"}
{"prompt": "Write a Python function to calculate the area of a rectangle.", "code": "def rectangle_area(length, width):\n    return length * width"}
{"prompt": "Write a Python function to calculate the circumference of a circle.", "code": "import math\ndef circle_circumference(radius):\n    return 2 * math.pi * radius"}
{"prompt": "Write a Python function to calculate the area of a circle.", "code": "import math\ndef circle_area(radius):\n    return math.pi * radius**2"}
{"prompt": "Write a Python function to convert Celsius to Fahrenheit.", "code": "def celsius_to_fahrenheit(celsius):\n    return (celsius * 9/5) + 32"}
{"prompt": "Write a Python function to convert Fahrenheit to Celsius.", "code": "def fahrenheit_to_celsius(fahrenheit):\n    return (fahrenheit - 32) * 5/9"}
{"prompt": "Write a Python function to check if a number is even.", "code": "def is_even(n):\n    return n % 2 == 0"}
{"prompt": "Write a Python function to check if a number is odd.", "code": "def is_odd(n):\n    return n % 2 != 0"}
{"prompt": "Write a Python function to find the maximum of two numbers.", "code": "def find_max(a, b):\n    if a > b:\n        return a\n    else:\n        return b"}
{"prompt": "Write a Python function to find the minimum of two numbers.", "code": "def find_min(a, b):\n    if a < b:\n        return a\n    else:\n        return b"}
{"prompt": "Write a Python function to calculate the sum of numbers in a list.", "code": "def sum_list(numbers):\n    total = 0\n    for num in numbers:\n        total += num\n    return total"}
{"prompt": "Write a Python function to calculate the average of numbers in a list.", "code": "def average_list(numbers):\n    if not numbers:\n        return 0\n    return sum(numbers) / len(numbers)"}
{"prompt": "Write a Python function to find the largest number in a list.", "code": "def find_largest(numbers):\n    if not numbers:\n        return None\n    largest = numbers[0]\n    for num in numbers:\n        if num > largest:\n            largest = num\n    return largest"}
{"prompt": "Write a Python function to find the smallest number in a list.", "code": "def find_smallest(numbers):\n    if not numbers:\n        return None\n    smallest = numbers[0]\n    for num in numbers:\n        if num < smallest:\n            smallest = num\n    return smallest"}
{"prompt": "Write a Python function to reverse a string.", "code": "def reverse_string(s):\n    return s[::-1]"}
{"prompt": "Write a Python function to check if a string is a palindrome.", "code": "def is_palindrome(s):\n    return s == s[::-1]"}
{"prompt": "Write a Python function to count the number of vowels in a string.", "code": "def count_vowels(s):\n    vowels = 'aeiouAEIOU'\n    count = 0\n    for char in s:\n        if char in vowels:\n            count += 1\n    return count"}
{"prompt": "Write a Python function to convert a string to uppercase.", "code": "def to_uppercase(s):\n    return s.upper()"}
{"prompt": "Write a Python function to convert a string to lowercase.", "code": "def to_lowercase(s):\n    return s.lower()"}
{"prompt": "Write a Python function to find the length of a string.", "code": "def string_length(s):\n    return len(s)"}
{"prompt": "Write a Python function to check if a list is empty.", "code": "def is_list_empty(lst):\n    return len(lst) == 0"}
{"prompt": "Write a Python function to append an element to a list.", "code": "def append_to_list(lst, element):\n    lst.append(element)\n    return lst"}
{"prompt": "Write a Python function to remove an element from a list.", "code": "def remove_from_list(lst, element):\n    if element in lst:\n        lst.remove(element)\n    return lst"}
{"prompt": "Write a Python function to sort a list of numbers in ascending order.", "code": "def sort_list_ascending(numbers):\n    return sorted(numbers)"}
{"prompt": "Write a Python function to sort a list of numbers in descending order.", "code": "def sort_list_descending(numbers):\n    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):\n    try:\n        return lst.index(element)\n    except ValueError:\n        return -1"}
{"prompt": "Write a Python function to check if an element exists in a list.", "code": "def element_exists(lst, element):\n    return element in lst"}
{"prompt": "Write a Python function to get the first element of a list.", "code": "def get_first_element(lst):\n    if lst:\n        return lst[0]\n    else:\n        return None"}
{"prompt": "Write a Python function to get the last element of a list.", "code": "def get_last_element(lst):\n    if lst:\n        return lst[-1]\n    else:\n        return None"}
{"prompt": "Write a Python function to create a dictionary from two lists (keys and values).", "code": "def create_dictionary(keys, values):\n    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):\n    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):\n    d[key] = value\n    return d"}
{"prompt": "Write a Python function to remove a key-value pair from a dictionary.", "code": "def remove_from_dictionary(d, key):\n    if key in d:\n        del d[key]\n    return d"}
{"prompt": "Write a Python function to check if a key exists in a dictionary.", "code": "def key_exists_in_dictionary(d, key):\n    return key in d"}
{"prompt": "Write a Python program to get user input and print it.", "code": "user_input = input('Enter something: ')\nprint('You entered:', user_input)"}
{"prompt": "Write a Python function to greet a user by name.", "code": "def greet_user(name):\n    return f'Hello, {name}!'"}
{"prompt": "Write a Python function to calculate the square of a number.", "code": "def square_number(n):\n    return n * n"}
{"prompt": "Write a Python function to calculate the cube of a number.", "code": "def cube_number(n):\n    return n ** 3"}
{"prompt": "Write a Python function to check if a year is a leap year.", "code": "def is_leap_year(year):\n    if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):\n        return True\n    else:\n        return False"}
{"prompt": "Write a Python function to count occurrences of a character in a string.", "code": "def count_character(s, char):\n    return s.count(char)"}
{"prompt": "Write a Python function to find the absolute value of a number.", "code": "def absolute_value(n):\n    return abs(n)"}
{"prompt": "Write a Python function to generate a sequence of numbers.", "code": "def generate_sequence(start, end, step):\n    return list(range(start, end, step))"}
{"prompt": "Write a Python function to check if a list contains duplicates.", "code": "def has_duplicates(lst):\n    return len(lst) != len(set(lst))"}
{"prompt": "Write a Python function to get the current date.", "code": "from datetime import date\ndef get_current_date():\n    return date.today()"}
{"prompt": "Write a Python function to get the current time.", "code": "from datetime import datetime\ndef get_current_time():\n    return datetime.now().time()"}
{"prompt": "Write a Python function to simulate a simple coin flip (Heads or Tails).", "code": "import random\ndef coin_flip():\n    return random.choice(['Heads', 'Tails'])"}