messages listlengths 2 2 | conversation_id int64 0 20k |
|---|---|
[
{
"content": "Create an array of length 5 which contains all even numbers between 1 and 10.",
"role": "user"
},
{
"content": "arr = [2, 4, 6, 8, 10]",
"role": "assistant"
}
] | 0 |
[
{
"content": "Formulate an equation to calculate the height of a triangle given the angle, side lengths and opposite side length.",
"role": "user"
},
{
"content": "Height of triangle = opposite side length * sin (angle) / side length",
"role": "assistant"
}
] | 1 |
[
{
"content": "Write a replace method for a string class which replaces the given string with a given set of characters.\nstring = \"Hello World!\"\nreplace_with = \"Greetings!\"",
"role": "user"
},
{
"content": "def replace(self, replace_with):\n new_string = \"\"\n for char in self:\n ... | 2 |
[
{
"content": "Create an array of length 15 containing numbers divisible by 3 up to 45.",
"role": "user"
},
{
"content": "arr = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45]",
"role": "assistant"
}
] | 3 |
[
{
"content": "Write a function to find the number of distinct states in a given matrix.\nmatrix = [[1, 0, 0],\n [1, 0, 1],\n [1, 1, 1]]",
"role": "user"
},
{
"content": "def find_num_distinct_states(matrix):\n states = set()\n for row in matrix:\n state = \"\".join([st... | 4 |
[
{
"content": "Create a nested loop to print every combination of numbers between 0-9",
"role": "user"
},
{
"content": "for i in range(10):\n for j in range(10):\n print(i, j)",
"role": "assistant"
}
] | 5 |
[
{
"content": "Write a function to find the maximum difference between two numbers in a given array.\narr = [5, 3, 17, 11, 9]",
"role": "user"
},
{
"content": "def max_difference(arr):\n max_diff = 0\n for i in range(len(arr)-1):\n diff = arr[i+1] - arr[i]\n if diff > max_diff:\n ... | 6 |
[
{
"content": "Write a function to generate the nth Fibonacci number.\n< noinput >",
"role": "user"
},
{
"content": "def fib(n):\n if n == 0:\n return 0\n elif n == 1:\n return 1\n else:\n return fib(n-2) + fib(n-1)",
"role": "assistant"
}
] | 7 |
[
{
"content": "Write a class to represent a 2D point with x and y coordinates.",
"role": "user"
},
{
"content": "class Point:\n def __init__(self, x, y):\n self.x = x \n self.y = y \n \n def __str__(self): \n return \"({0},{1})\".format(self.x, self.y)",
"role": "assi... | 8 |
[
{
"content": "Write code that removes spaces from a given string.\nstring = \" A B C D \"",
"role": "user"
},
{
"content": "def remove_spaces(string): \n return \"\".join(string.split())",
"role": "assistant"
}
] | 9 |
[
{
"content": "Write a function that checks if a give number is even or odd.",
"role": "user"
},
{
"content": "def is_even(n):\n if n%2 == 0:\n return True \n else:\n return False",
"role": "assistant"
}
] | 10 |
[
{
"content": "Write code to create a list of all prime numbers between 2 and 100.",
"role": "user"
},
{
"content": "def find_primes(n): \n prime_list = [2] \n for number in range(2, n + 1): \n is_prime = True\n for k in range(2, number): \n if number % k == 0: \n ... | 11 |
[
{
"content": "Edit the following code to print out all even numbers from 1 to 10.\nfor i in range(1,11):\n print(i)",
"role": "user"
},
{
"content": "for i in range(1,11):\n if i % 2 == 0:\n print(i)",
"role": "assistant"
}
] | 12 |
[
{
"content": "Write code to find the sum of all numbers between 1 and 10.",
"role": "user"
},
{
"content": "sum = 0\nfor i in range(1,11):\n sum += i\nprint(sum)",
"role": "assistant"
}
] | 13 |
[
{
"content": "Create a function to calculate the area of a given circle.",
"role": "user"
},
{
"content": "def area_circle(radius):\n return 3.14 * (radius**2)",
"role": "assistant"
}
] | 14 |
[
{
"content": "Follow the comments in the code to complete the program which prints a conversion table from Fahrenheit to Celsius.\n# This program prints a conversion table from Fahrenheit to Celsius\n\n# Print a heading for the table\n# TODO\n\n# Print the column headings\n# TODO\n\n# Calculate and print the ta... | 15 |
[
{
"content": "Develop a classification algorithm in Python to predict whether a bird is a hawk or a falcon.",
"role": "user"
},
{
"content": "import pandas as pd\nimport numpy as np\n\n# Define features\nfeatures = [\"wing_shape\", \"size\", \"tails_length\", \"color_pattern\"] \n\n# Load the data\n... | 16 |
[
{
"content": "Create a function in Java for computing the factorial of a positive integer number.",
"role": "user"
},
{
"content": "public static long factorial(int n) {\n if (n == 0) {\n return 1;\n }\n long result = 1;\n for (int i = 1; i <= n; i++) {\n result *= i;\n ... | 17 |
[
{
"content": "Create a C++ program for randomly shuffling an array of integers.",
"role": "user"
},
{
"content": "#include <iostream>\n#include <algorithm>\n#include <random>\n\nvoid shuffleArray(int array[], int size) {\n\tstd::random_device rd;\n\tstd::mt19937 g(rd()); \n\tstd::shuffle(array, arra... | 18 |
[
{
"content": "Use the function to debug the given program and prevent the segmentation fault.\n#include <stdio.h>\n\nint main() {\n int array[] = {1, 2, 3, 4, 5};\n int n = 5;\n int i;\n // TODO\n for (i = 0; i <= n; i++) {\n printf(\"%d\\n\", array[i]);\n }\n return 0;\n}",
"rol... | 19 |
[
{
"content": "Replace the placeholder with a for loop for iterating over the numbers from 1 to n and printing them.\nfor i in range(n):\n # TODO",
"role": "user"
},
{
"content": "for i in range(1, n+1):\n print(i)",
"role": "assistant"
}
] | 20 |
[
{
"content": "Use try-except statements to detect and handle exceptions in the code.\nfor i in range(n):\n x = 1/i",
"role": "user"
},
{
"content": "try:\n for i in range(n):\n x = 1/i\nexcept ZeroDivisionError:\n print(\"Zero division error encountered!\")",
"role": "assistant"
... | 21 |
[
{
"content": "Re-write the code segment as a list comprehension.\nnumbers = []\nfor i in range(10):\n if i % 2 == 0:\n numbers.append(i)",
"role": "user"
},
{
"content": "numbers = [i for i in range(10) if i % 2 == 0]",
"role": "assistant"
}
] | 22 |
[
{
"content": "Remove the boilerplate code from the program for printing 10 random numbers.\nimport random\n\n# Generate 10 random numbers\nfor i in range(10):\n # TODO",
"role": "user"
},
{
"content": "import random\n\n# Generate 10 random numbers\nfor i in range(10):\n print(random.randrange(... | 23 |
[
{
"content": "Modify the code to perform the mathematical expression “x to the power of y”.\n# Calculate x to the power of y\n# TODO",
"role": "user"
},
{
"content": "# Calculate x to the power of y\nx_pow_y = x**y",
"role": "assistant"
}
] | 24 |
[
{
"content": "Create a dictionary for counting the occurrence of each letter in the given string.\nstring = \"hello world\"\n#TODO",
"role": "user"
},
{
"content": "string = \"hello world\"\nletter_counts = {}\n\nfor letter in string:\n if letter in letter_counts:\n letter_counts[letter] +=... | 25 |
[
{
"content": "Follow the comments to complete the code that finds the maximum value in an array.\n# Find the maximum value in an array\narr = [4, 5, 2, 8, 7]\n# TODO",
"role": "user"
},
{
"content": "# Find the maximum value in an array\narr = [4, 5, 2, 8, 7]\n\nmax_value = arr[0]\nfor i in range(1,... | 26 |
[
{
"content": "Write a function in HTML for creating a table of n rows and m columns.",
"role": "user"
},
{
"content": "<table>\n <tbody>\n <% for (let i = 0; i < n; i++) { %>\n <tr>\n <% for (let j = 0; j < m; j++) { %>\n <td>Cell Content</td>\n <% } %>\n </tr>\n... | 27 |
[
{
"content": "Create a CSS script that centers the login form on the webpage.",
"role": "user"
},
{
"content": ".login-form {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n}",
"role": "assistant"
}
] | 28 |
[
{
"content": "Create a Java program that prints out the sum of the numbers in the array.\nint[] numbers = {1, 2, 3 , 4, 5};",
"role": "user"
},
{
"content": "public class SumOfArray {\n public static void main(String[] args) {\n int[] numbers = {1, 2, 3 , 4, 5};\n int sum = 0;\n ... | 29 |
[
{
"content": "Write a SQL query to calculate the total number of orders in the \"orders\" table.",
"role": "user"
},
{
"content": "SELECT COUNT(*) AS \"Total Number of Orders\" \nFROM orders;",
"role": "assistant"
}
] | 30 |
[
{
"content": "Write a Python function to convert a given string to lowercase.\nstring = \"FOO\"",
"role": "user"
},
{
"content": "def to_lowercase(string):\n return string.lower()\n\nstring = \"FOO\"\nprint(to_lowercase(string))",
"role": "assistant"
}
] | 31 |
[
{
"content": "Create a C program that prints out the Fibonacci sequence.",
"role": "user"
},
{
"content": "#include <stdio.h>\n\nint main()\n{\n int i, num, first=0, second=1, next;\n printf(\"Enter the number of elements: \");\n scanf(\"%d\", &num);\n printf(\"Fibonacci Series: \");\n ... | 32 |
[
{
"content": "Write a function in JavaScript to count the number of vowels in a given string.\nconst string = \"abcdefg\"",
"role": "user"
},
{
"content": "function countVowels(string) {\n let vowelCount = 0;\n const vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"];\n \n for (let i = 0; i < string... | 33 |
[
{
"content": "Create a JSX code that renders a \"Hello, World!\" message in the browser.",
"role": "user"
},
{
"content": "import React from \"react\";\n\nfunction App() {\n return (\n <div>\n <h1>Hello, World!</h1>\n </div>\n );\n}\n\nexport default App;",
"role": "assistant"
}
] | 34 |
[
{
"content": "Write an SQL query to calculate the average order price for each product category in the \"orders\" table.",
"role": "user"
},
{
"content": "SELECT category, AVG(price) as \"Average Order Price\"\nFROM orders\nGROUP BY category;",
"role": "assistant"
}
] | 35 |
[
{
"content": "Create a Java program that prints out the contents of a given two-dimensional array.\nint[][] arr = {{1,2},{3,4},{5,6}}",
"role": "user"
},
{
"content": "public class TwoDArray {\n\n public static void main(String[] args) {\n int[][] arr = {{1,2},{3,4},{5,6}};\n\n for(... | 36 |
[
{
"content": "Create a C++ program that sorts a given array in descending order.\nint array[] = {6, 3, 8, 12, 9, 4};",
"role": "user"
},
{
"content": "#include<iostream>\nusing namespace std;\n \nint main()\n{\n int array[] = {6, 3, 8, 12, 9, 4};\n int arraySize = sizeof(array)/sizeof(array[0]... | 37 |
[
{
"content": "Edit the Python code so that it prints out the total number of elements in the list.\nlist = [1, 2, 3, 4, 5]",
"role": "user"
},
{
"content": "list = [1, 2, 3, 4, 5]\nprint(\"Total number of elements in the list: \", len(list))",
"role": "assistant"
}
] | 38 |
[
{
"content": "Create a Swift code that show the number of days in the given month.\nint month = 5",
"role": "user"
},
{
"content": "let month = 5\nlet daysEndingInth = [3, 0, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3]\nlet daysInMonth = daysEndingInth[month - 1] \nprint(\"The number of days in the month of \\(mo... | 39 |
[
{
"content": "Write a HTML code that create a form for user to fill out their current address.",
"role": "user"
},
{
"content": "<form action=\"\">\n <label for=\"street\">Street</label>\n <input type=\"text\" name=\"street\" id=\"street\">\n <label for=\"city\">City</label>\n <input typ... | 40 |
[
{
"content": "Write a SQL query to find the total number of orders placed between two given dates.\nstart_date = '2020-01-01'\nend_date = '2020-02-01'",
"role": "user"
},
{
"content": "SELECT COUNT(*)\nFROM orders\nWHERE order_date BETWEEN '2020-01-01' AND '2020-02-01';",
"role": "assistant"
}... | 41 |
[
{
"content": "Create a Ruby code that prints out the median of a given array of numbers.\nnums = [1, 7, 3, 6]",
"role": "user"
},
{
"content": "nums = [1, 7, 3, 6]\nsorted_nums = nums.sort\n\n# Calculation of median \nif sorted_nums.length % 2 == 0\n mid_index = sorted_nums.length/2\n median = (so... | 42 |
[
{
"content": "Create a PHP code to check if an array contains a given item.\n$input_array = array(1,2,3,4,5);\n$item_to_check = 3;",
"role": "user"
},
{
"content": "<?php\n$input_array = array(1,2,3,4,5);\n$item_to_check = 3;\n\nif(in_array($item_to_check, $input_array)) {\n echo \"Array contains t... | 43 |
[
{
"content": "Edit the code to create a try-except block to handle the exception.\na = 5\nb = 0\n\nans = a/b",
"role": "user"
},
{
"content": "try:\n a = 5\n b = 0\n\n ans = a/b\nexcept ZeroDivisionError:\n print(\"Cannot divide by zero.\")",
"role": "assistant"
}
] | 44 |
[
{
"content": "Write a script using Bash that replaces all vowels with a number.",
"role": "user"
},
{
"content": "#!/bin/bash\n\nstring=\"Hello World!\"\nvowels=(\"a\" \"e\" \"i\" \"o\" \"u\" \"A\" \"E\" \"I\" \"O\" \"U\")\n\nfor i in \"${vowels[@]}\"\ndo\n string=\"${string//$i/0}\"\ndone\n\nech... | 45 |
[
{
"content": "Change the variable `x` to the data type desired.\nx = 'Hello World!'",
"role": "user"
},
{
"content": "x = \"Hello World!\"",
"role": "assistant"
}
] | 46 |
[
{
"content": "Create a function that takes an array as an argument and returns the sum of all the elements in the array.\narr = [1, 2, 3, 4, 5]",
"role": "user"
},
{
"content": "def arraySum(arr):\n total = 0\n for num in arr:\n total += num\n return total",
"role": "assistant"
... | 47 |
[
{
"content": "Sort the array in ascending order.\narr = [3, 2, 1, 5, 4]",
"role": "user"
},
{
"content": "arr.sort() # [1, 2, 3, 4, 5]",
"role": "assistant"
}
] | 48 |
[
{
"content": "Generate a random integer between 4 and 8 (inclusively).",
"role": "user"
},
{
"content": "import random\nx = random.randint(4, 8)",
"role": "assistant"
}
] | 49 |
[
{
"content": "Write a list comprehension to square each number in the list.\narr = [1, 2, 3, 4, 5]",
"role": "user"
},
{
"content": "arr = [x**2 for x in arr] # [1, 4, 9, 16, 25]",
"role": "assistant"
}
] | 50 |
[
{
"content": "Write a function that takes a string and reverses the words.\ntext = \"Hello World!\"",
"role": "user"
},
{
"content": "def reverseWords(text):\n return ' '.join(text.split()[::-1])\n\nreverseWords(text) # \"World! Hello\"",
"role": "assistant"
}
] | 51 |
[
{
"content": "Write a SQL query to return the sum of all salaries.",
"role": "user"
},
{
"content": "SELECT SUM(salary)\nFROM employees;",
"role": "assistant"
}
] | 52 |
[
{
"content": "Create a function that takes in two numbers as arguments and returns the product of the two.",
"role": "user"
},
{
"content": "def multiply(x, y):\n return x*y",
"role": "assistant"
}
] | 53 |
[
{
"content": "Sum up the numbers in the array in Javascript.\narr = [1,2,3,4,5]",
"role": "user"
},
{
"content": "let sum = arr.reduce((total, num) => total + num);\nconsole.log(sum); // 15",
"role": "assistant"
}
] | 54 |
[
{
"content": "Using the given function, create a loop that counts from 0 to 9.\nfunction printNum(num){\n console.log(num)\n}",
"role": "user"
},
{
"content": "for (let i = 0; i < 10; i++){\n printNum(i);\n}",
"role": "assistant"
}
] | 55 |
[
{
"content": "Create a JSON object with three key-value pairs.",
"role": "user"
},
{
"content": "{\n \"firstName\": \"John\",\n \"lastName\": \"Doe\",\n \"age\": 30\n}",
"role": "assistant"
}
] | 56 |
[
{
"content": "Count the number of characters in the string.\ntext = \"Hello World!\"",
"role": "user"
},
{
"content": "len(text) # 12",
"role": "assistant"
}
] | 57 |
[
{
"content": "Generate a random number between 0 and 1 (inclusively).",
"role": "user"
},
{
"content": "Math.random(); // a random number between 0 and 1 (inclusively)",
"role": "assistant"
}
] | 58 |
[
{
"content": "Compose a function named average_list which takes a list of numbers as its argument and computes the average.",
"role": "user"
},
{
"content": "def average_list(nums):\n return sum(nums)/len(nums)",
"role": "assistant"
}
] | 59 |
[
{
"content": "Generate a snippet of code to extract all the URLs from the given string.\nThis string contains some urls such as https://www.google.com and https://www.facebook.com.",
"role": "user"
},
{
"content": "import re\n\nstring = \"This string contains some urls such as https://www.google.com... | 60 |
[
{
"content": "Write a code to convert a given spredsheet in csv format to json format.",
"role": "user"
},
{
"content": "import csv\nimport json\n\ndef csv_to_json():\n # Path of csv file\n file_csv = 'mycsvfile.csv'\n \n # Path of json file\n file_json = 'myjsonfile.json'\n \n ... | 61 |
[
{
"content": "Create a list comprehension to generate a list of multiples of 3 from 0 to 23.",
"role": "user"
},
{
"content": "list_of_multiples_of_3 = [x*3 for x in range(8)]",
"role": "assistant"
}
] | 62 |
[
{
"content": "Design a program to find the longest element in the given list.\n[10, 100, 200, 500, 400]",
"role": "user"
},
{
"content": "def longest_element(list):\n max_length = 0\n max_length_item = None\n\n for item in list:\n if len(item) > max_length:\n max_length = len(item)\n ... | 63 |
[
{
"content": "Write a function to print all prime numbers between two given numbers.",
"role": "user"
},
{
"content": "def print_prime_numbers_in_range(start, end):\n # start = starting number\n # end = ending number\n\n for num in range(start, end+1):\n # Prime numbers are greater than 1\n ... | 64 |
[
{
"content": "Describe the basic syntax of a Java function?",
"role": "user"
},
{
"content": "A Java function consists of a function name, return type, parameters (arguments), and body. The syntax of a Java function is as follows: \npublic <return type> <function name>(<list of parameters>) { \n ... | 65 |
[
{
"content": "How to reverse a list in C++?",
"role": "user"
},
{
"content": "You can reverse a list in C++ using the std::reverse algorithm. To reverse the list, pass the list as the first parameter and the beginning and end of the list as the second and third parameter, respectively. Alternatively... | 66 |
[
{
"content": "Write a SQL query to update a value x in a column y in a table z.\nx = 5, y = 'amount' and z = 'payments'.",
"role": "user"
},
{
"content": "UPDATE payments \nSET amount = 5 \nWHERE payments.amount IS NOT NULL;",
"role": "assistant"
}
] | 67 |
[
{
"content": "Write an algorithm in Python to determine if a number is even or odd.",
"role": "user"
},
{
"content": "def is_even(num): \n if num % 2 == 0: \n return True \n else: \n return False",
"role": "assistant"
}
] | 68 |
[
{
"content": "What is the purpose of a constructor in a class in Java?",
"role": "user"
},
{
"content": "The purpose of a constructor in a class in Java is to initialize an object of that class. A constructor is a special kind of method that is used to create an object of its associated class. When ... | 69 |
[
{
"content": "Write a JavaScript code to get the current browser URL.",
"role": "user"
},
{
"content": "var currentURL = window.location.href;\nconsole.log(currentURL);",
"role": "assistant"
}
] | 70 |
[
{
"content": "Rewrite the following C++ code using only pointer references instead of array subscripts:\nint arr[3] = {1,2,3};\nint sum = 0;\nfor (int i = 0; i < 3; i++) \n{\n sum += arr[i];\n}",
"role": "user"
},
{
"content": "int arr[3] = {1,2,3};\nint sum = 0;\nint* ptr = arr;\nfor (int i = 0;... | 71 |
[
{
"content": "Write a MySQL query to print the column names of a table named 'employees'.",
"role": "user"
},
{
"content": "SELECT column_name FROM information_schema.columns WHERE table_name = 'employees';",
"role": "assistant"
}
] | 72 |
[
{
"content": "Generate a regular expression to match a valid email address.",
"role": "user"
},
{
"content": "/^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5})$/",
"role": "assistant"
}
] | 73 |
[
{
"content": "How to delete a particular row in an SQLite database table?",
"role": "user"
},
{
"content": "To delete a particular row in an SQLite database table, you can use the DELETE statement with a WHERE clause to specify the row to be deleted. For example: DELETE FROM table_name WHERE conditi... | 74 |
[
{
"content": "Is it possible to set a breakpoint that is not associated with any source code line in a GDB program?",
"role": "user"
},
{
"content": "Yes, it is possible to set a breakpoint that is not associated with any source code line in a GDB program. For example, you can set a breakpoint on a ... | 75 |
[
{
"content": "Write a C++ code to find the average of an array of integers.",
"role": "user"
},
{
"content": "#include <iostream>\n\nint calculateAverage(int array[], int n){\n int sum = 0; \n for (int i=0; i<n; i++){\n sum += array[i]; \n } \n int average = sum/n;\n return ave... | 76 |
[
{
"content": "How can we encrypt a string in Python?",
"role": "user"
},
{
"content": "We can encrypt a string in Python using the cryptography module. The cryptography module provides high level cryptographic primitives using the Fernet cipher. The Fernet cipher uses AES-128 in CBC mode and PKCS7 p... | 77 |
[
{
"content": "What is the purpose of declaring a function as static in C++?",
"role": "user"
},
{
"content": "The purpose of declaring a function as static in C++ is to restrict its visibility to only the translation unit in which it is declared. A static function can only be called from within the ... | 78 |
[
{
"content": "How to print the elements of a two-dimensional array in C?",
"role": "user"
},
{
"content": "We can use nested loops to print the elements of a two-dimensional array in C. The outer loop iterates over the rows, while the inner loop iterates over the columns. For example, the following ... | 79 |
[
{
"content": "Using the following code, clean up the bugs and make sure the output functions correctly.\ndef example_func(lst):\n for element in lst:\n if (type(element) == int):\n lst.append(element + 5)\n return lst\n \nexample_func([1, 2, \"hello\"])",
"role": "user"
},
{
"conten... | 80 |
[
{
"content": "Write a C++ function to generate a random integer between 0 and 10.",
"role": "user"
},
{
"content": "#include <iostream> \n#include <cstdlib> \n#include <ctime> \nusing namespace std; \n\nint randomIntGenerator() \n{ \n // Setting the seed \n srand(time(0)); \n\n // Generating r... | 81 |
[
{
"content": "Create a table to store customer information.",
"role": "user"
},
{
"content": "CREATE TABLE customers (\n id int NOT NULL AUTO_INCREMENT,\n name varchar(100) NOT NULL,\n email varchar(100) NOT NULL,\n phone varchar(20) NOT NULL,\n address varchar(200) NOT NULL,\n PRIMARY K... | 82 |
[
{
"content": "Create a class in Java named Puppy that has two instance variables, age and name and two methods, bark and sleep.",
"role": "user"
},
{
"content": "public class Puppy { \n // Instance Variables \n String name; \n int age; \n \n // Constructor \n public Puppy(String name, int... | 83 |
[
{
"content": "Parse the string and return the number of unique alphabets in the string.\nStringInput = \"apple\"",
"role": "user"
},
{
"content": "int count = 0;\nfor (int i = 0; i < StringInput.length(); i++) {\n if ((StringInput.charAt(i) >= 'a' && StringInput.charAt(i) <= 'z') || (StringInput.ch... | 84 |
[
{
"content": "Write a shell script to print the top 3 most frequently used commands.",
"role": "user"
},
{
"content": "#!/bin/bash\n# Store all commands used in the last hour in command_list.\nhistory | tail -$(($(date +%H) * 60)) -n $(($(date +%M)+1)) | cut -d ' ' -f 5 > command_list\n# Create fre... | 85 |
[
{
"content": "Read the JSON string below and convert it into a dictionary.\njsonString = '{\"name\": \"John\", \"age\": 30, \"city\": \"New York\"}'",
"role": "user"
},
{
"content": "import json\n\njsonObject = json.loads(jsonString)\ndictionary = dict(jsonObject)\nprint(dictionary)",
"role": "a... | 86 |
[
{
"content": "Implement a function that finds the maximum element in a given array.\narr = [45, 7, 0, 82, 23]",
"role": "user"
},
{
"content": "def find_max_element(arr): \n max_element = arr[0] \n for index in range(1, len(arr)): \n if arr[index] > max_element: \n max_elemen... | 87 |
[
{
"content": "Validate whether the string contains only alphabets or not.\nmyString = \"abc123\"",
"role": "user"
},
{
"content": "def check_string_alphabets(myString):\n for character in myString:\n if (not character.isalpha()):\n return False\n return True\n\nmyString = \"a... | 88 |
[
{
"content": "Rewrite the following code using ternary operator.\nnum1 = 5\nnum2 = 10\n\nif num1 < num2:\n print(\"num1 is smaller than num2\")\nelse:\n print(\"num1 is greater than or equal to num2\")",
"role": "user"
},
{
"content": "num1 = 5\nnum2 = 10\n\nprint(\"num1 is smaller than num2\"... | 89 |
[
{
"content": "Write a script to check if a given number is a palindrome or not.\ninputNumber = 121",
"role": "user"
},
{
"content": "# Function to check whether the inputNumber is palindrome or not\ndef is_palindrome(inputNumber):\n\n # negative numbers are not palindrome\n if inputNumber < 0:\n... | 90 |
[
{
"content": "Edit the following code to remove the bugs.\ndef reverse_string(user_string): \n if len(user_string) == 0: \n return \"\" \n else: \n return reverse_string(user_string[1:]) + user_string[0] \n \nprint(reverse_string(“test”))",
"role": "user"
},
{
"content": "def reverse_stri... | 91 |
[
{
"content": "What is the output of the following code?\nlist1 = ['a', 'b', 'c']\nlist2 = [1, 2, 3]\n\nfor x, y in zip(list1, list2):\n print(x * y)",
"role": "user"
},
{
"content": "a\nbb\nccc",
"role": "assistant"
}
] | 92 |
[
{
"content": "Write a function to remove all whitespace characters from a given string.\nmyString = \"Hello World \"",
"role": "user"
},
{
"content": "def remove_whitespaces(myString):\n return ''.join(myString.split())\n\nmyString = \"Hello World \"\nprint(remove_whitespaces(myString))... | 93 |
[
{
"content": "Edit the following code to add try catch block.\nx = \"5\"\ny = \"2\"\nsum = int(x) + int(y)\nprint(\"Sum of x and y is\", sum)",
"role": "user"
},
{
"content": "x = \"5\"\ny = \"2\"\ntry:\n sum = int(x) + int(y)\n print(\"Sum of x and y is\", sum)\nexcept:\n print(\"Error: Inval... | 94 |
[
{
"content": "Write a Python function that takes two lists of equal length and creates a dictionary of the elements in each list that have the same index.\nlist_one = [1, 2, 3, 4]\nlist_two = [\"a\", \"b\", \"c\", \"d\"]",
"role": "user"
},
{
"content": "def list_dict(list_one, list_two):\n \"\"\... | 95 |
[
{
"content": "Create a quick-sort algorithm in Python.",
"role": "user"
},
{
"content": "def quick_sort(arr):\n \"\"\"Sort a list of numbers in ascending order using the Quick-Sort algorithm\"\"\"\n if len(arr) == 0:\n return []\n\n pivot = arr[0]\n left_arr = [x for x in arr if x... | 96 |
[
{
"content": "Develop an algorithm to find the value of n where n is the index of the Fibonacci sequence.",
"role": "user"
},
{
"content": "def nth_fibonacci_number(n):\n \"\"\"Find the value of n where n is the index of the Fibonacci Sequence.\"\"\" \n if n < 2:\n return n \n elif n... | 97 |
[
{
"content": "Create a program that finds all the prime numbers less than or equal to a given number.",
"role": "user"
},
{
"content": "def find_primes(num):\n \"\"\"Find all the prime numbers less than or equal to a given number.\"\"\"\n primes = []\n for i in range(2, num + 1):\n i... | 98 |
[
{
"content": "Write a function that takes in a list of numbers and prints out the greatest number.\nlist = [8, 2, 14, 25]",
"role": "user"
},
{
"content": "def find_greatest(list):\n \"\"\"Print out the greatest number from a list of numbers.\"\"\"\n greatest = list[0]\n for num in list:\n ... | 99 |
End of preview. Expand in Data Studio
- Downloads last month
- 5