prompt:
Write a function to add two numbers.

def add_two(a, b):

tests:
assert add_two(2, 3) == 5
assert add_two(10, 5) == 15
assert add_two(-1, 1) == 0


prompt:
Write a function to multiply two numbers.

def multiply_two(a, b):

tests:
assert multiply_two(2, 3) == 6
assert multiply_two(4, 5) == 20
assert multiply_two(0, 9) == 0


square

prompt:
Write a function to return the square of a number.

def square(n):

tests:
assert square(2) == 4
assert square(5) == 25
assert square(0) == 0


cube

prompt:
Write a function to return the cube of a number.

def cube(n):

tests:
assert cube(2) == 8
assert cube(3) == 27
assert cube(1) == 1


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

def is_even(n):

tests:
assert is_even(4) == True
assert is_even(7) == False
assert is_even(0) == True


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

def is_odd(n):

tests:
assert is_odd(3) == True
assert is_odd(8) == False
assert is_odd(1) == True


absolute

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

def absolute(n):

tests:
assert absolute(-5) == 5
assert absolute(5) == 5
assert absolute(0) == 0


prompt:
Write a function to return the larger of two numbers.

def max_two(a, b):

tests:
assert max_two(3, 5) == 5
assert max_two(9, 2) == 9
assert max_two(4, 4) == 4


prompt:
Write a function to return the smaller of two numbers.

def min_two(a, b):

tests:
assert min_two(3, 5) == 3
assert min_two(9, 2) == 2
assert min_two(4, 4) == 4


factorial

prompt:
Write a function to compute the factorial of a non-negative integer.

def factorial(n):

tests:
assert factorial(0) == 1
assert factorial(4) == 24
assert factorial(6) == 720


prompt:
Write a function to check if a number is positive.

def is_positive(n):

tests:
assert is_positive(5) == True
assert is_positive(-3) == False
assert is_positive(0) == False


double

prompt:
Write a function to return double a number.

def double(n):

tests:
assert double(3) == 6
assert double(10) == 20
assert double(0) == 0


half

prompt:
Write a function to return half of a number using integer division.

def half(n):

tests:
assert half(10) == 5
assert half(7) == 3
assert half(0) == 0


sign

prompt:
Write a function that returns 1 if the number is positive, -1 if negative, 0 if zero.

def sign(n):

tests:
assert sign(5) == 1
assert sign(-2) == -1
assert sign(0) == 0


power

prompt:
Write a function to raise a to the power b.

def power(a, b):

tests:
assert power(2, 3) == 8
assert power(5, 2) == 25
assert power(3, 0) == 1


mod

prompt:
Write a function to return a modulo b.

def mod(a, b):

tests:
assert mod(10, 3) == 1
assert mod(9, 4) == 1
assert mod(8, 2) == 0


prompt:
Write a function to check if a is a multiple of b.

def is_multiple(a, b):

tests:
assert is_multiple(10, 5) == True
assert is_multiple(9, 4) == False
assert is_multiple(12, 3) == True


prompt:
Write a function to count the number of digits in a positive integer.

def digit_count(n):

tests:
assert digit_count(5) == 1
assert digit_count(123) == 3
assert digit_count(99999) == 5


prompt:
Write a function to return the sum of all integers from 1 to n.

def sum_to_n(n):

tests:
assert sum_to_n(5) == 15
assert sum_to_n(10) == 55
assert sum_to_n(1) == 1


prompt:
Write a function to return the sum of a list of numbers.

def sum_list(nums):


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

def max_list(nums):

tests:
assert max_list([1, 5, 3]) == 5
assert max_list([9, 2, 7]) == 9
assert max_list([4]) == 4


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

def min_list(nums):

tests:
assert min_list([1, 5, 3]) == 1
assert min_list([9, 2, 7]) == 2
assert min_list([4]) == 4


prompt:
Write a function to return the number of elements in a list.

def length_list(lst):

tests:
assert length_list([1, 2, 3]) == 3
assert length_list([]) == 0
assert length_list([5, 5, 5, 5]) == 4


average

prompt:
Write a function to return the average of a list of numbers.

def average(nums):

tests:
assert average([2, 4]) == 3.0
assert average([1, 2, 3]) == 2.0
assert average([10]) == 10.0


prompt:
Write a function to count the positive numbers in a list.

def count_positives(nums):

tests:
assert count_positives([1, -2, 3]) == 2
assert count_positives([-1, -2]) == 0
assert count_positives([5, 5]) == 2


prompt:
Write a function to return the sum of the even numbers in a list.

def sum_even(nums):


prompt:
Write a function to return a list of the even numbers from the input list.

def filter_even(nums):

tests:
assert filter_even([1, 2, 3, 4]) == [2, 4]
assert filter_even([5, 6, 7]) == [6]
assert filter_even([2]) == [2]


prompt:
Write a function to return a list of the odd numbers from the input list.

def filter_odd(nums):


prompt:
Write a function to return the list reversed.

def reverse_list(lst):

tests:
assert reverse_list([1, 2, 3]) == [3, 2, 1]
assert reverse_list([9]) == [9]
assert reverse_list([4, 5]) == [5, 4]


prompt:
Write a function to return the sorted list of unique elements.

def unique_list(lst):


prompt:
Write a function to count how many times x appears in a list.

def count_element(lst, x):

tests:
assert count_element([1, 2, 2, 3], 2) == 2
assert count_element([5, 5, 5], 5) == 3
assert count_element([1, 2], 9) == 0


contains

prompt:
Write a function to check if x is in the list.

def contains(lst, x):

tests:
assert contains([1, 2, 3], 2) == True
assert contains([5, 6], 9) == False
assert contains([], 1) == False


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

def first_element(lst):

tests:
assert first_element([1, 2, 3]) == 1
assert first_element([9, 8]) == 9
assert first_element([5]) == 5


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

def last_element(lst):

tests:
assert last_element([1, 2, 3]) == 3
assert last_element([9, 8]) == 8
assert last_element([5]) == 5


prompt:
Write a function to return the product of all numbers in a list.

def product_list(nums):

tests:
assert product_list([1, 2, 3]) == 6
assert product_list([4, 5]) == 20
assert product_list([2, 2, 2]) == 8


prompt:
Write a function to return the difference between the largest and smallest element.

def max_minus_min(nums):

tests:
assert max_minus_min([1, 5, 3]) == 4
assert max_minus_min([9, 2]) == 7
assert max_minus_min([4, 4]) == 0


prompt:
Write a function to count elements greater than k.

def count_greater(nums, k):

tests:
assert count_greater([1, 5, 3], 2) == 2
assert count_greater([9, 2], 5) == 1
assert count_greater([1, 2], 9) == 0


prompt:
Write a function to return a list with every element doubled.

def double_all(nums):


prompt:
Write a function to add k to every element of a list.

def add_to_all(nums, k):


prompt:
Write a function to return the list sorted in ascending order.

def sort_list(lst):


prompt:
Write a function to return the list sorted in descending order.

def sort_desc(lst):


prompt:
Write a function to return the second largest element in a list.

def second_largest(nums):

tests:
assert second_largest([1, 5, 3]) == 3
assert second_largest([9, 2, 7]) == 7
assert second_largest([4, 4, 5]) == 4


prompt:
Write a function to reverse a string.

def reverse_string(s):

tests:
assert reverse_string('hello') == 'olleh'
assert reverse_string('abc') == 'cba'
assert reverse_string('x') == 'x'


prompt:
Write a function to return the length of a string.

def string_length(s):

tests:
assert string_length('hello') == 5
assert string_length('') == 0
assert string_length('ab') == 2


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

def to_upper(s):

tests:
assert to_upper('hello') == 'HELLO'
assert to_upper('Abc') == 'ABC'
assert to_upper('x') == 'X'


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

def to_lower(s):

tests:
assert to_lower('HELLO') == 'hello'
assert to_lower('Abc') == 'abc'
assert to_lower('X') == 'x'


prompt:
Write a function to return the first character of a string.

def first_char(s):

tests:
assert first_char('hello') == 'h'
assert first_char('abc') == 'a'
assert first_char('x') == 'x'


prompt:
Write a function to return the last character of a string.

def last_char(s):

tests:
assert last_char('hello') == 'o'
assert last_char('abc') == 'c'
assert last_char('x') == 'x'


prompt:
Write a function to count how many times character c appears in string s.

def count_char(s, c):

tests:
assert count_char('banana', 'a') == 3
assert count_char('hello', 'l') == 2
assert count_char('abc', 'z') == 0


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

def is_palindrome(s):

tests:
assert is_palindrome('racecar') == True
assert is_palindrome('hello') == False
assert is_palindrome('aba') == True


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

def count_vowels(s):

tests:
assert count_vowels('hello') == 2
assert count_vowels('sky') == 0
assert count_vowels('aeiou') == 5


prompt:
Write a function to repeat a string n times.

def repeat_string(s, n):

tests:
assert repeat_string('ab', 3) == 'ababab'
assert repeat_string('x', 5) == 'xxxxx'
assert repeat_string('hi', 1) == 'hi'


prompt:
Write a function to capitalize the first letter of a string.

def capitalize_first(s):

tests:
assert capitalize_first('hello') == 'Hello'
assert capitalize_first('world') == 'World'
assert capitalize_first('a') == 'A'


prompt:
Write a function to count the number of words in a sentence.

def count_words(s):

tests:
assert count_words('hello world') == 2
assert count_words('one') == 1
assert count_words('a b c d') == 4


prompt:
Write a function to remove all spaces from a string.

def remove_spaces(s):

tests:
assert remove_spaces('a b c') == 'abc'
assert remove_spaces('hello world') == 'helloworld'
assert remove_spaces('x') == 'x'


prompt:
Write a function to check if string s starts with prefix p.

def starts_with(s, p):

tests:
assert starts_with('hello', 'he') == True
assert starts_with('world', 'wo') == True
assert starts_with('abc', 'z') == False


prompt:
Write a function to check if string s ends with suffix p.

def ends_with(s, p):

tests:
assert ends_with('hello', 'lo') == True
assert ends_with('world', 'ld') == True
assert ends_with('abc', 'z') == False


concat

prompt:
Write a function to concatenate two strings.

def concat(a, b):

tests:
assert concat('foo', 'bar') == 'foobar'
assert concat('a', 'b') == 'ab'
assert concat('hi', '') == 'hi'


prompt:
Write a function to check if a string is empty.

def is_empty(s):

tests:
assert is_empty('') == True
assert is_empty('a') == False
assert is_empty('hello') == False


prompt:
Write a function to return the character at index i of string s.

def nth_char(s, i):

tests:
assert nth_char('hello', 1) == 'e'
assert nth_char('world', 0) == 'w'
assert nth_char('abc', 2) == 'c'


swapcase

prompt:
Write a function to swap the case of every letter in a string.

def swapcase(s):

tests:
assert swapcase('Hello') == 'hELLO'
assert swapcase('aBc') == 'AbC'
assert swapcase('XyZ') == 'xYz'


prompt:
Write a function to count the uppercase letters in a string.

def count_upper(s):

tests:
assert count_upper('Hello') == 1
assert count_upper('ABC') == 3
assert count_upper('abc') == 0