[output] | sum_of_digits = 0 num = 1234 while num > 0: digit = num % 10 sum_of_digits += digit num //= 10 print(sum_of_digits) #Output: 10 [instruction] | Calculate the total sum of digits in the given integer. [input] | 1234
[output] | my_list = [3, 5, 7, 9, 5, 3, 7] unique_list = list(set(my_list)) print(unique_list) #Output: [3, 5, 7, 9] [instruction] | Create a program which takes a given list and returns a list with only the unique elements. [input] | [3, 5, 7, 9, 5, 3, 7]
[output] | public class User { private String name; private int age; private String email; // getters and setters public User(String name, int age, String email) { this.name = name; this.age = age; this.email = email; } } [instruction] | Design a Java class to store user information. [input] |
[output] | def reverse(head): prev = None curr = head while(curr is not None): next = curr.next curr.next = prev prev = curr curr = next head = prev return head [instruction] | Design an algorithm in Python for reversing a linked list. [input] |
[output] | DELETE FROM users WHERE status = 'Inactive'; [instruction] | Create a database query in MySQL to delete "Inactive" status records from a table named 'users'. [input] |
[output] | function cloneObject(obj) { let clone = {}; for (let key in obj) { if (typeof obj[key] === 'object') { clone[key] = cloneObject(obj[key]); } else { clone[key] = obj[key]; } } return clone; } [instruction] | Write a function in JavaScript to create and return a copy of an object. [input] |
[output] | def find_peak(arr): max_h = arr[0] max_i = 0 # traverse the array for i in range(len(arr)): if arr[i] > max_h: max_h = arr[i] max_i = i return max_h, max_i [instruction] | Create a function that finds the highest peak in an array of elevation data. [input] | [9, 10, 12, 15, 7, 8, 11]
[output] | dict1 = {"A":"Apple","B":"Banana","C":"Cherry"} for key in dict1: print(dict1[key]) # Output Apple Banana Cherry [instruction] | Using the dictionary provided, write a code to print out the values in the dictionary. [input] | dict1 = {"A":"Apple","B":"Banana","C":"Cherry"}
[output] | def calc_mean(nums): """ Calculate the mean of a list of integers """ if len(nums) == 0: return 0 else: sum_of_nums = sum(nums) mean = sum_of_nums/len(nums) return mean nums = [10, 20, 30, 40, 50] mean = calc_mean(nums) print(mean) # 30 [instruction] | Write a code to calculate the mean of the list of integers provided. [input] | nums = [10, 20, 30, 40, 50]
[output] | def divisible_by_each_other(num1, num2): """ A function to check whether two numbers are divisible by each other """ if num1 % num2 == 0 or num2 % num1 == 0: return True else: return False num1 = 8 num2 = 4 result = divisible_by_each_other(num1, num2) print(resu [instruction] | Write a code to check whether two numbers are divisible by each other. [input] | num1 = 8 num2 = 4
[output] | def find_common(list1, list2): """ Find all common elements in two list and store it in a new list """ new_list = [] for item1 in list1: for item2 in list2: if item1 == item2: new_list.append(item1) return new_list list1 = [instruction] | Create a code to find all common elements in two list and store it in a new list. [input] | list1 = [1, 2, 3, 4, 5] list2 = [3, 4, 5, 6, 7]
[output] | def longest_word_in_string(string): """ A function to print out the longest word in a given string """ words = string.split(" ") longest_word = max(words, key=len) return longest_word test_string = "This is an example sentence." longest = longest_word_in_string(test_string [instruction] | For the given string, write a code to print out the longest word in the string. [input] | test_string = "This is an example sentence."
[output] | def create_list(start, end): """ Create a code to generate a list of all numbers between a given start and end number """ number_list = [] for num in range(start, end+1): number_list.append(num) return number_list start = 10 end = 20 result = create_list(start, end) [instruction] | Create a code to generate a list of all numbers between a given start and end number. [input] | start = 10 end = 20
[output] | def generate_list(): return list(range(11)) [instruction] | Write a function to generate a list of integers from 0 to 10. [input] |
[output] | def add_x(x, y): return x + y [instruction] | Reimplement the function below, so that it takes in two int arguments and returns their sum instead of using the existing global variable x. [input] | x = 4 def add_x(y): return x + y
[output] | def extract_odd_numbers(numbers): return [x for x in numbers if x % 2 != 0] [instruction] | Given a list of integers, write a function that takes the list and returns only the odd numbers in the list. [input] |
[output] | def calc_factorial(x): if x == 0: return 1 else: return x * calc_factorial(x - 1) [instruction] | Rewrite the following function so that it takes in an int argument and returns the factorial of that number. [input] | def calc_factorial(x): total = 1 if x == 0: return 1 for num in range(1, x+1): total *= num return total
[output] | #include<iostream> using namespace std; int partition (int arr[], int low, int high) { int pivot = arr[high]; // pivot int i = (low - 1); // Index of smaller element for (int j = low; j <= high- 1; j++) { if (arr[j] <= pivot) { i++; // increment [instruction] | Generate a C++ program that sorts the elements in an array using the quick sort algorithm. [input] |
[output] | def remove_punctuation(s): punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~''' s_without_punct = "" for char in s: if char not in punctuations: s_without_punct = s_without_punct + char return s_without_punct [instruction] | Generate a python code program that removes punctuation from a given string. [input] |
[output] | def median(arr): arr.sort() if len(arr)%2 != 0: return arr[len(arr)//2] else: return (arr[(len(arr)//2)-1]+arr[len(arr)//2])/2 [instruction] | Generate a program that accepts an integer array and returns its median value [input] |
[output] | for i in range(1,501): num = i**2 if num < 501: print(num) [instruction] | Generate a code that prints out all the perfect squares between 1 and 500. [input] |
[output] | <div> <p>Status: <span class='status'>off</span> <button onclick="toggleStatus()">Toggle</button> </p> <script> function toggleStatus() { $('.status').text($('.status').text() === 'off' ? 'on' : 'off'); } </script> </div> [instruction] | Using jQuery, update the HTML code to provide the user a toggle switch that changes the text from "off" to "on" when clicked. [input] | <div> <p>Status: <span class='status'>off</span></p> </div>
[output] | console.log("Hello, World!"); [instruction] | Use JavaScript to print out the string "Hello, World!". [input] |
[output] | <html> <body> <form> <input type="checkbox" /> </form> </body> </html> [instruction] | Create an HTML page with a form containing a checkbox. [input] |
[output] | function isValidEmail(email) { // Regular expression for validating an email address const re = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/; return re.test(String(email).toLowerCase()); } [instruction] | Write a function in JavaScript to verify that a given email address is valid or not. [input] |
[output] | <html> <head> <style> .table { display: table; width: 100%; } .table-row { display: table-row; } .table-cell { display: table-cell; } </style> </head> <body> <div class="table"> <div class="table-row"> [instruction] | Using HTML and CSS, create a page layout with two columns and a header row. [input] |
[output] | public static int averageOfTwoIntegers(int a, int b) { return (a + b) / 2; } [instruction] | Implement a function in Java that finds the average of two given integers. [input] |
[output] | $ javac HelloWorld.java $ java HelloWorld HelloWorld [instruction] | Compile this Java program and output the result. [input] | public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } }
[output] | docker run --name some-postgres -e POSTGRES_PASSWORD=mySecretPassword -d postgres [instruction] | Setup a postgres database using Docker. [input] |
[output] | SELECT COUNT(*) FROM Houses WHERE bedrooms = 4; [instruction] | Construct an SQL query to count the number of houses with four bedrooms. [input] |