Datasets:
name stringlengths 3 16 | prompt stringlengths 54 109 | func_prompt stringlengths 54 109 | tests stringlengths 60 125 | setup_code stringclasses 1
value |
|---|---|---|---|---|
add_two | Write a function to add two numbers.
def add_two(a, b): | Write a function to add two numbers.
def add_two(a, b): | assert add_two(2, 3) == 5
assert add_two(10, 5) == 15
assert add_two(-1, 1) == 0 | |
multiply_two | Write a function to multiply two numbers.
def multiply_two(a, b): | Write a function to multiply two numbers.
def multiply_two(a, b): | assert multiply_two(2, 3) == 6
assert multiply_two(4, 5) == 20
assert multiply_two(0, 9) == 0 | |
square | Write a function to return the square of a number.
def square(n): | Write a function to return the square of a number.
def square(n): | assert square(2) == 4
assert square(5) == 25
assert square(0) == 0 | |
cube | Write a function to return the cube of a number.
def cube(n): | Write a function to return the cube of a number.
def cube(n): | assert cube(2) == 8
assert cube(3) == 27
assert cube(1) == 1 | |
is_even | Write a function to check if a number is even.
def is_even(n): | Write a function to check if a number is even.
def is_even(n): | assert is_even(4) == True
assert is_even(7) == False
assert is_even(0) == True | |
is_odd | Write a function to check if a number is odd.
def is_odd(n): | Write a function to check if a number is odd.
def is_odd(n): | assert is_odd(3) == True
assert is_odd(8) == False
assert is_odd(1) == True | |
absolute | Write a function to return the absolute value of a number.
def absolute(n): | Write a function to return the absolute value of a number.
def absolute(n): | assert absolute(-5) == 5
assert absolute(5) == 5
assert absolute(0) == 0 | |
max_two | Write a function to return the larger of two numbers.
def max_two(a, b): | Write a function to return the larger of two numbers.
def max_two(a, b): | assert max_two(3, 5) == 5
assert max_two(9, 2) == 9
assert max_two(4, 4) == 4 | |
min_two | Write a function to return the smaller of two numbers.
def min_two(a, b): | Write a function to return the smaller of two numbers.
def min_two(a, b): | assert min_two(3, 5) == 3
assert min_two(9, 2) == 2
assert min_two(4, 4) == 4 | |
factorial | Write a function to compute the factorial of a non-negative integer.
def factorial(n): | Write a function to compute the factorial of a non-negative integer.
def factorial(n): | assert factorial(0) == 1
assert factorial(4) == 24
assert factorial(6) == 720 | |
is_positive | Write a function to check if a number is positive.
def is_positive(n): | Write a function to check if a number is positive.
def is_positive(n): | assert is_positive(5) == True
assert is_positive(-3) == False
assert is_positive(0) == False | |
double | Write a function to return double a number.
def double(n): | Write a function to return double a number.
def double(n): | assert double(3) == 6
assert double(10) == 20
assert double(0) == 0 | |
half | Write a function to return half of a number using integer division.
def half(n): | Write a function to return half of a number using integer division.
def half(n): | assert half(10) == 5
assert half(7) == 3
assert half(0) == 0 | |
sign | Write a function that returns 1 if the number is positive, -1 if negative, 0 if zero.
def sign(n): | Write a function that returns 1 if the number is positive, -1 if negative, 0 if zero.
def sign(n): | assert sign(5) == 1
assert sign(-2) == -1
assert sign(0) == 0 | |
power | Write a function to raise a to the power b.
def power(a, b): | Write a function to raise a to the power b.
def power(a, b): | assert power(2, 3) == 8
assert power(5, 2) == 25
assert power(3, 0) == 1 | |
mod | Write a function to return a modulo b.
def mod(a, b): | Write a function to return a modulo b.
def mod(a, b): | assert mod(10, 3) == 1
assert mod(9, 4) == 1
assert mod(8, 2) == 0 | |
is_multiple | Write a function to check if a is a multiple of b.
def is_multiple(a, b): | Write a function to check if a is a multiple of b.
def is_multiple(a, b): | assert is_multiple(10, 5) == True
assert is_multiple(9, 4) == False
assert is_multiple(12, 3) == True | |
digit_count | Write a function to count the number of digits in a positive integer.
def digit_count(n): | Write a function to count the number of digits in a positive integer.
def digit_count(n): | assert digit_count(5) == 1
assert digit_count(123) == 3
assert digit_count(99999) == 5 | |
sum_to_n | Write a function to return the sum of all integers from 1 to n.
def sum_to_n(n): | Write a function to return the sum of all integers from 1 to n.
def sum_to_n(n): | assert sum_to_n(5) == 15
assert sum_to_n(10) == 55
assert sum_to_n(1) == 1 | |
sum_list | Write a function to return the sum of a list of numbers.
def sum_list(nums): | Write a function to return the sum of a list of numbers.
def sum_list(nums): | assert sum_list([1, 2, 3]) == 6
assert sum_list([10, 20]) == 30
assert sum_list([-1, 1, 5]) == 5 | |
max_list | Write a function to return the largest number in a list.
def max_list(nums): | Write a function to return the largest number in a list.
def max_list(nums): | assert max_list([1, 5, 3]) == 5
assert max_list([9, 2, 7]) == 9
assert max_list([4]) == 4 | |
min_list | Write a function to return the smallest number in a list.
def min_list(nums): | Write a function to return the smallest number in a list.
def min_list(nums): | assert min_list([1, 5, 3]) == 1
assert min_list([9, 2, 7]) == 2
assert min_list([4]) == 4 | |
length_list | Write a function to return the number of elements in a list.
def length_list(lst): | Write a function to return the number of elements in a list.
def length_list(lst): | assert length_list([1, 2, 3]) == 3
assert length_list([]) == 0
assert length_list([5, 5, 5, 5]) == 4 | |
average | Write a function to return the average of a list of numbers.
def average(nums): | Write a function to return the average of a list of numbers.
def average(nums): | assert average([2, 4]) == 3.0
assert average([1, 2, 3]) == 2.0
assert average([10]) == 10.0 | |
count_positives | Write a function to count the positive numbers in a list.
def count_positives(nums): | Write a function to count the positive numbers in a list.
def count_positives(nums): | assert count_positives([1, -2, 3]) == 2
assert count_positives([-1, -2]) == 0
assert count_positives([5, 5]) == 2 | |
sum_even | Write a function to return the sum of the even numbers in a list.
def sum_even(nums): | Write a function to return the sum of the even numbers in a list.
def sum_even(nums): | assert sum_even([1, 2, 3, 4]) == 6
assert sum_even([2, 4, 6]) == 12
assert sum_even([1, 3]) == 0 | |
filter_even | Write a function to return a list of the even numbers from the input list.
def filter_even(nums): | Write a function to return a list of the even numbers from the input list.
def filter_even(nums): | assert filter_even([1, 2, 3, 4]) == [2, 4]
assert filter_even([5, 6, 7]) == [6]
assert filter_even([2]) == [2] | |
filter_odd | Write a function to return a list of the odd numbers from the input list.
def filter_odd(nums): | Write a function to return a list of the odd numbers from the input list.
def filter_odd(nums): | assert filter_odd([1, 2, 3, 4]) == [1, 3]
assert filter_odd([5, 6, 7]) == [5, 7]
assert filter_odd([2]) == [] | |
reverse_list | Write a function to return the list reversed.
def reverse_list(lst): | Write a function to return the list reversed.
def reverse_list(lst): | assert reverse_list([1, 2, 3]) == [3, 2, 1]
assert reverse_list([9]) == [9]
assert reverse_list([4, 5]) == [5, 4] | |
unique_list | Write a function to return the sorted list of unique elements.
def unique_list(lst): | Write a function to return the sorted list of unique elements.
def unique_list(lst): | assert unique_list([1, 2, 2, 3]) == [1, 2, 3]
assert unique_list([5, 5, 5]) == [5]
assert unique_list([3, 1, 2]) == [1, 2, 3] | |
count_element | Write a function to count how many times x appears in a list.
def count_element(lst, x): | Write a function to count how many times x appears in a list.
def count_element(lst, x): | 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 | Write a function to check if x is in the list.
def contains(lst, x): | Write a function to check if x is in the list.
def contains(lst, x): | assert contains([1, 2, 3], 2) == True
assert contains([5, 6], 9) == False
assert contains([], 1) == False | |
first_element | Write a function to return the first element of a list.
def first_element(lst): | Write a function to return the first element of a list.
def first_element(lst): | assert first_element([1, 2, 3]) == 1
assert first_element([9, 8]) == 9
assert first_element([5]) == 5 | |
last_element | Write a function to return the last element of a list.
def last_element(lst): | Write a function to return the last element of a list.
def last_element(lst): | assert last_element([1, 2, 3]) == 3
assert last_element([9, 8]) == 8
assert last_element([5]) == 5 | |
product_list | Write a function to return the product of all numbers in a list.
def product_list(nums): | Write a function to return the product of all numbers in a list.
def product_list(nums): | assert product_list([1, 2, 3]) == 6
assert product_list([4, 5]) == 20
assert product_list([2, 2, 2]) == 8 | |
max_minus_min | Write a function to return the difference between the largest and smallest element.
def max_minus_min(nums): | Write a function to return the difference between the largest and smallest element.
def max_minus_min(nums): | assert max_minus_min([1, 5, 3]) == 4
assert max_minus_min([9, 2]) == 7
assert max_minus_min([4, 4]) == 0 | |
count_greater | Write a function to count elements greater than k.
def count_greater(nums, k): | Write a function to count elements greater than k.
def count_greater(nums, k): | assert count_greater([1, 5, 3], 2) == 2
assert count_greater([9, 2], 5) == 1
assert count_greater([1, 2], 9) == 0 | |
double_all | Write a function to return a list with every element doubled.
def double_all(nums): | Write a function to return a list with every element doubled.
def double_all(nums): | assert double_all([1, 2, 3]) == [2, 4, 6]
assert double_all([5]) == [10]
assert double_all([0, 4]) == [0, 8] | |
add_to_all | Write a function to add k to every element of a list.
def add_to_all(nums, k): | Write a function to add k to every element of a list.
def add_to_all(nums, k): | assert add_to_all([1, 2, 3], 10) == [11, 12, 13]
assert add_to_all([5], 1) == [6]
assert add_to_all([0], 0) == [0] | |
sort_list | Write a function to return the list sorted in ascending order.
def sort_list(lst): | Write a function to return the list sorted in ascending order.
def sort_list(lst): | assert sort_list([3, 1, 2]) == [1, 2, 3]
assert sort_list([9, 5, 7]) == [5, 7, 9]
assert sort_list([1]) == [1] | |
sort_desc | Write a function to return the list sorted in descending order.
def sort_desc(lst): | Write a function to return the list sorted in descending order.
def sort_desc(lst): | assert sort_desc([3, 1, 2]) == [3, 2, 1]
assert sort_desc([9, 5, 7]) == [9, 7, 5]
assert sort_desc([1]) == [1] | |
second_largest | Write a function to return the second largest element in a list.
def second_largest(nums): | Write a function to return the second largest element in a list.
def second_largest(nums): | assert second_largest([1, 5, 3]) == 3
assert second_largest([9, 2, 7]) == 7
assert second_largest([4, 4, 5]) == 4 | |
reverse_string | Write a function to reverse a string.
def reverse_string(s): | Write a function to reverse a string.
def reverse_string(s): | assert reverse_string('hello') == 'olleh'
assert reverse_string('abc') == 'cba'
assert reverse_string('x') == 'x' | |
string_length | Write a function to return the length of a string.
def string_length(s): | Write a function to return the length of a string.
def string_length(s): | assert string_length('hello') == 5
assert string_length('') == 0
assert string_length('ab') == 2 | |
to_upper | Write a function to convert a string to uppercase.
def to_upper(s): | Write a function to convert a string to uppercase.
def to_upper(s): | assert to_upper('hello') == 'HELLO'
assert to_upper('Abc') == 'ABC'
assert to_upper('x') == 'X' | |
to_lower | Write a function to convert a string to lowercase.
def to_lower(s): | Write a function to convert a string to lowercase.
def to_lower(s): | assert to_lower('HELLO') == 'hello'
assert to_lower('Abc') == 'abc'
assert to_lower('X') == 'x' | |
first_char | Write a function to return the first character of a string.
def first_char(s): | Write a function to return the first character of a string.
def first_char(s): | assert first_char('hello') == 'h'
assert first_char('abc') == 'a'
assert first_char('x') == 'x' | |
last_char | Write a function to return the last character of a string.
def last_char(s): | Write a function to return the last character of a string.
def last_char(s): | assert last_char('hello') == 'o'
assert last_char('abc') == 'c'
assert last_char('x') == 'x' | |
count_char | Write a function to count how many times character c appears in string s.
def count_char(s, c): | Write a function to count how many times character c appears in string s.
def count_char(s, c): | assert count_char('banana', 'a') == 3
assert count_char('hello', 'l') == 2
assert count_char('abc', 'z') == 0 | |
is_palindrome | Write a function to check if a string is a palindrome.
def is_palindrome(s): | Write a function to check if a string is a palindrome.
def is_palindrome(s): | assert is_palindrome('racecar') == True
assert is_palindrome('hello') == False
assert is_palindrome('aba') == True | |
count_vowels | Write a function to count the vowels in a string.
def count_vowels(s): | Write a function to count the vowels in a string.
def count_vowels(s): | assert count_vowels('hello') == 2
assert count_vowels('sky') == 0
assert count_vowels('aeiou') == 5 | |
repeat_string | Write a function to repeat a string n times.
def repeat_string(s, n): | Write a function to repeat a string n times.
def repeat_string(s, n): | assert repeat_string('ab', 3) == 'ababab'
assert repeat_string('x', 5) == 'xxxxx'
assert repeat_string('hi', 1) == 'hi' | |
capitalize_first | Write a function to capitalize the first letter of a string.
def capitalize_first(s): | Write a function to capitalize the first letter of a string.
def capitalize_first(s): | assert capitalize_first('hello') == 'Hello'
assert capitalize_first('world') == 'World'
assert capitalize_first('a') == 'A' | |
count_words | Write a function to count the number of words in a sentence.
def count_words(s): | Write a function to count the number of words in a sentence.
def count_words(s): | assert count_words('hello world') == 2
assert count_words('one') == 1
assert count_words('a b c d') == 4 | |
remove_spaces | Write a function to remove all spaces from a string.
def remove_spaces(s): | Write a function to remove all spaces from a string.
def remove_spaces(s): | assert remove_spaces('a b c') == 'abc'
assert remove_spaces('hello world') == 'helloworld'
assert remove_spaces('x') == 'x' | |
starts_with | Write a function to check if string s starts with prefix p.
def starts_with(s, p): | Write a function to check if string s starts with prefix p.
def starts_with(s, p): | assert starts_with('hello', 'he') == True
assert starts_with('world', 'wo') == True
assert starts_with('abc', 'z') == False | |
ends_with | Write a function to check if string s ends with suffix p.
def ends_with(s, p): | Write a function to check if string s ends with suffix p.
def ends_with(s, p): | assert ends_with('hello', 'lo') == True
assert ends_with('world', 'ld') == True
assert ends_with('abc', 'z') == False | |
concat | Write a function to concatenate two strings.
def concat(a, b): | Write a function to concatenate two strings.
def concat(a, b): | assert concat('foo', 'bar') == 'foobar'
assert concat('a', 'b') == 'ab'
assert concat('hi', '') == 'hi' | |
is_empty | Write a function to check if a string is empty.
def is_empty(s): | Write a function to check if a string is empty.
def is_empty(s): | assert is_empty('') == True
assert is_empty('a') == False
assert is_empty('hello') == False | |
nth_char | Write a function to return the character at index i of string s.
def nth_char(s, i): | Write a function to return the character at index i of string s.
def nth_char(s, i): | assert nth_char('hello', 1) == 'e'
assert nth_char('world', 0) == 'w'
assert nth_char('abc', 2) == 'c' | |
swapcase | Write a function to swap the case of every letter in a string.
def swapcase(s): | Write a function to swap the case of every letter in a string.
def swapcase(s): | assert swapcase('Hello') == 'hELLO'
assert swapcase('aBc') == 'AbC'
assert swapcase('XyZ') == 'xYz' | |
count_upper | Write a function to count the uppercase letters in a string.
def count_upper(s): | Write a function to count the uppercase letters in a string.
def count_upper(s): | assert count_upper('Hello') == 1
assert count_upper('ABC') == 3
assert count_upper('abc') == 0 |
simple-python-grpo
A curated set of simple Python function problems for GRPO / RLVR fine-tuning. Each row has a natural-language description, a function signature, and 3 auto-verified test assertions (generated by running a reference implementation, so every test is correct by construction). The reference is NOT included — the model must generate the body and is rewarded when the tests pass.
Fields: name, prompt, func_prompt, tests (newline-separated asserts),
setup_code.
Built for the Union/Flyte GRPO code tutorial. Deliberately homogeneous and simple so a small model (e.g. Qwen2.5-0.5B) can learn a transferable pattern.
- Downloads last month
- 5