[output] | my_dict = {1:1, 2:2, 3:3, 4:4, 5:5} [instruction] | Convert the following list into a dictionary in Python: [1, 2, 3, 4, 5]. [input] |
[output] | <html> <head> <title>My Web Page</title> </head> <body> <!-- content goes here --> </body> <footer> <!-- footer content goes here --> </footer> </html> [instruction] | Create a HTML web page with a header, a body and a footer section. [input] |
[output] | def reverseStr(string): reversedString = "" for i in range(len(string) -1, -1, -1): reversedString += string[i] return reversedString [instruction] | Generate code for a function that takes a string and returns its reverse. [input] |
[output] | <table> <tr> <th>Film Name</th> <th>Release Year</th> </tr> <tr> <td>Harry Potter</td> <td>2001</td> </tr> <tr> <td>Avengers</td> <td>2012</td> </tr> </table> [instruction] | Write a two-column HTML table with the film names as the first column and the release year as the second column. [input] | Harry Potter (2001) Avengers (2012) <noinput>
[output] | .myClass { width: 400px; height: 200px; border: 3px dotted yellow; } [instruction] | Design a CSS class with a width of 400px and a height of 200px and a border of 3px dotted yellow. [input] |
[output] | import string import random def generate_random_string(length): allowed_characters = string.ascii_lowercase return ''.join(random.choices(allowed_characters, k=length)) random_string = generate_random_string(5) print(random_string) [instruction] | Generate a random string of length 5 with only lowercase alphabetic characters. [input] |
[output] | x = lambda a : a[0] print(x("Hello")) [instruction] | Write a lambda expression to show the first character of a string. [input] |
[output] | def fibonacci(n): f1 = 0 f2 = 1 sum_fib = 0 for i in range(2, n + 1): next_term = f1 + f2 sum_fib += next_term f1 = f2 f2 = next_term return sum_fib print(fibonacci(7)) [instruction] | Write a Python program to find the sum of Fibonacci numbers till the number 7. [input] |
[output] | def equals(str1, str2): """Compares two strings to see if they are equal.""" return str1 == str2 [instruction] | Implement a comparison operator that takes two strings as arguments and returns true if the strings are equal and false otherwise. [input] |
[output] | def get_name(): """Gets a user's full name .""" first_name = input("What is your first name? ") last_name = input("What is your last name? ") return first_name + " " + last_name if __name__ == '__main__': name = get_name() print("Your name is", name) [instruction] | Write a Python program that uses the function "get_name" to ask the user for their full name and then prints it back to them. [input] |
[output] | def goodbye_world(string): """Replaces the word Hello with Goodbye in the string.""" return string.replace("Hello", "Goodbye") [instruction] | Manipulate the string "Hello, World!" using the correct Python function that will replace the word "Hello" with "Goodbye". [input] |
[output] | def is_sum_even(num1, num2): """Checks if the product of two numbers is even or odd.""" sum = num1 * num2 return sum % 2 == 0 if __name__ == "__main__": is_even = is_sum_even(8, 12) print("Is the sum even? ", is_even) [instruction] | Write code to take two numbers and determine if their product is even. [input] | 8, 12
[output] | def sort_list(numbers): """Sorts a list of numbers according to the last three digits of each number.""" return sorted(numbers, key=lambda x: x % 1000) [instruction] | Sort the given list according to the last three digits of every number. [input] | [332, 555, 898, 876]
[output] | def remove_duplicates(string): """Removes all repeated words from a string.""" words = string.split() seen = set() result = [] for word in words: if word not in seen: seen.add(word) result.append(word) return " ".join(result) [instruction] | Take a string and remove all the duplicated words within it. [input] |
[output] | date = '2020-12-30' import datetime def getDayofWeek(date): # Convert the string to datetime d = datetime.datetime.strptime(date, "%Y-%m-%d") # Return the day of the week return d.strftime("%A") print(f"The day of the week for {date} is {getDayofWeek(date)}.") [instruction] | Write a function that returns the day of the week given a date. [input] | date = '2020-12-30'
[output] | x = 10 y = 15 z = 5 # Find the maximum max_val = max(x, y, z) print(f"The maximum among {x}, {y}, and {z} is {max_val}.") [instruction] | Given three numbers, write a code to find the maximum among them. [input] | x = 10 y = 15 z = 5
[output] | arr = ["cat","dog","mouse"] # Check if the strings are unique def is_unique(arr): seen = set() for item in arr: if item in seen: return False seen.add(item) return True if is_unique(arr): print("All the strings in the sequence are unique.") else: pri [instruction] | Given a sequence of strings, write a code to check if all the strings in the sequence are unique. [input] | arr = ["cat","dog","mouse"]
[output] | def cipher(input_str, key): output_str = "" for char in input_str: if char.isalpha(): # Encrypt each character ascii_value = ord(char) ascii_value = ascii_value + (key % 26) if char.isupper(): if ascii_value > ord("Z"): ascii_value -= 26 elif [instruction] | Write a Python program to create a Caesar Cipher encryption algorithm. [input] |
[output] | SELECT DISTINCT * FROM table [instruction] | Write a SQL query to select only unique rows. [input] |
[output] | SELECT * FROM table ORDER BY column DESC [instruction] | Create a HQL query to sort records by descending order. [input] |
[output] | arr = [5, 7, 3, 8, 10] # Sort the array arr.sort() print(f"Sorted list: {arr}") [instruction] | Given a collection of integers, write a code to sort the integers in ascending order. [input] | arr = [5, 7, 3, 8, 10]
[output] | # Calculate the probability probability = mean(x > 5) print(f"Probability of getting a number greater than 5 from a range of 1 to 10 is {probability}.") [instruction] | Write an R statement to calculate the probability of getting a number greater than 5 from a range of 1 to 10. [input] |
[output] | def convert_list_to_str(list): return ";".join(list) print(convert_list_to_str(list)) [instruction] | Write a code to convert a list of comma or semicolon separated strings into a single string. [input] | list = ['apple', 'orange', 'banana']
[output] | def filter_3_5(nums): return [num for num in nums if num % 3 == 0 and num % 5 == 0] print(filter_3_5(list)) [instruction] | Write a code to filter out numbers which are divisible by 3 and 5 from a given list. [input] | list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[output] | print("Hello, World!") [instruction] | What is the Python equivalent of the C++ code snippet? [input] | #include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; }
[output] | <p>Hello, World!</p> [instruction] | Generate an HTML element which displays the phrase "Hello, World!" [input] |
[output] | class Car: def __init__(self, make, model, year): self.make = make self.model = model self.year = year [instruction] | Create a class named 'Car' with the given properties. [input] | class Car: Make, Model, Year
[output] | function calculateAge(birthYear) { let age = 2019 - birthYear; return age; } [instruction] | Create a JavaScript function named 'calculateAge' that determines a person's age based on the birth year given. [input] |
[output] | public String combine(String str1, String str2) { return str1+str2; } [instruction] | Create a method named 'combine' to combine two strings. [input] | String str1 = "Hello"; String str2 = "World";
[output] | function power(num, pow) { let result = 1; for (let i = 1; i <= pow; i++) { result *= num; } return result; } [instruction] | Create a function in JavaScript that takes in a number and a power, and returns the result of the power operation on the number. [input] | num = 2, pow = 5