conversations listlengths 2 2 |
|---|
[
{
"from": "human",
"value": "Create a function to calculate the sum of a sequence of integers."
},
{
"from": "gpt",
"value": "# Python code\ndef sum_sequence(sequence):\n sum = 0\n for num in sequence:\n sum += num\n return sum"
}
] |
[
{
"from": "human",
"value": "Generate a Python code for crawling a website for a specific type of data."
},
{
"from": "gpt",
"value": "import requests\nimport re\n\ndef crawl_website_for_phone_numbers(website):\n response = requests.get(website)\n phone_numbers = re.findall('\\d{3}-\\d{3}-... |
[
{
"from": "human",
"value": "Create a Python list comprehension to get the squared values of a list [1, 2, 3, 5, 8, 13]."
},
{
"from": "gpt",
"value": "[x*x for x in [1, 2, 3, 5, 8, 13]]"
}
] |
[
{
"from": "human",
"value": "Generate a python script to perform this action."
},
{
"from": "gpt",
"value": "def remove_duplicates(string): \n result = \"\" \n prev = '' \n\n for char in string:\n if char != prev: \n result += char\n prev = char\n return ... |
[
{
"from": "human",
"value": "Write a python script to generates random numbers between 0 and 9 that are divisible by 3."
},
{
"from": "gpt",
"value": "def generate_random_divisible_number():\n import random\n while True:\n # Generate a random number\n process = random.randint... |
[
{
"from": "human",
"value": "Write a Python code to get the third largest element in a given row."
},
{
"from": "gpt",
"value": "def third_largest(lst):\n if len(lst) < 3:\n return\n distinct = []\n for i in lst:\n if i not in distinct:\n distinct.append(i)\n ... |
[
{
"from": "human",
"value": "Generate a REST API with Python and Flask that allows users to create, read, update, and delete records from a database."
},
{
"from": "gpt",
"value": "from flask import Flask, request\nfrom flask_sqlalchemy import SQLAlchemy\n\napp = Flask(name)\napp.config['SQLALCH... |
[
{
"from": "human",
"value": "Create a Python function that takes in a string and a list of words and returns true if the string contains all the words in the list."
},
{
"from": "gpt",
"value": "def contains_words(input_string, words):\n for word in words:\n if word not in input_string:\n return... |
[
{
"from": "human",
"value": "What should this Python program do?"
},
{
"from": "gpt",
"value": "def is_palindrome(s):\n '''This function returns True if the string s is a palindrome and False if it isn't.''' \n return s == s[::-1] # Checks if s is the same as its reverse."
}
] |
[
{
"from": "human",
"value": "Create a Python program to sort and print out the elements of an array of integers."
},
{
"from": "gpt",
"value": "arr = [17, 41, 5, 22, 54, 6, 29, 3, 13]\n\narr.sort()\n\nprint(arr)\n\n# Output: [3, 5, 6, 13, 17, 22, 29, 41, 54]"
}
] |
[
{
"from": "human",
"value": "Generate a Python program that adds two then doubles the result."
},
{
"from": "gpt",
"value": "def double_add(num1, num2): \n return (num1 + num2) * 2"
}
] |
[
{
"from": "human",
"value": "Write a python program to extract the non-vowel words in a sentence."
},
{
"from": "gpt",
"value": "def extract_words(sentence):\n non_vowel_words = []\n words = sentence.split()\n vowels = ['a','e','i','o','u','A','E','I','O','U']\n for word in words:\n ... |
[
{
"from": "human",
"value": "Write a Python program to calculate the average of a list of positive integers and output the result."
},
{
"from": "gpt",
"value": "list_of_positive_integers = [1, 5, 6, 7, 8]\ntotal = sum(list_of_positive_integers)\n\navg = total/len(list_of_positive_integers)\n\np... |
[
{
"from": "human",
"value": "Develop a function in Python that prints out the Pascal's triangle for a given number of rows."
},
{
"from": "gpt",
"value": "def pascal_triangle(n): \n trow = [1] \n y = [0] \n for x in range(max(n, 0)): \n print(trow) \n trow=[l+r for l,r in ... |
[
{
"from": "human",
"value": "Implement a decision-making algorithm for a rock-paper-scissors game using Python."
},
{
"from": "gpt",
"value": "# Rock, paper, scissors game!\n\ndef play_game(player1, player2):\n # Define the winning rules\n rules = {'rock': 'scissors', 'scissors': 'paper',... |
[
{
"from": "human",
"value": "Collate a machine learning model in Python that distinguishes between cats and dogs."
},
{
"from": "gpt",
"value": "import numpy as np\nimport keras\nfrom keras.layers import Dense, Conv2D, MaxPooling2D, Dropout, Flatten\nfrom keras.models import Sequential\nfrom ker... |
[
{
"from": "human",
"value": "Write a Python program to find all the numbers divisible by a certain number within a certain range."
},
{
"from": "gpt",
"value": "def find_numbers_divisible_by(m, n, divisor):\n divisible_numbers = []\n for i in range(m, n+1):\n if i % divisor == 0:\n ... |
[
{
"from": "human",
"value": "Implement a Python function that will take two strings and return true if the first string contains the second."
},
{
"from": "gpt",
"value": "def check_contains(query, word): \n if query.find(word) != -1:\n return True\n return False\n\nresult = check_c... |
[
{
"from": "human",
"value": "Write an algorithm in Python 3 that calculates the factorial of a number."
},
{
"from": "gpt",
"value": "def factorial(n):\n if n == 0:\n return 1\n else:\n return n * factorial(n-1)"
}
] |
[
{
"from": "human",
"value": "Develop a Python function to predict the class labels of a given set of data."
},
{
"from": "gpt",
"value": "# Load the dataset\nimport pandas as pd\ncsv_url = 'http://test.test/test.csv'\ndf = pd.read_csv(csv_url)\n\n# Split the dataset into features and label\nX = ... |
[
{
"from": "human",
"value": "Develop a Python program to generate random passwords that consist of 8 characters."
},
{
"from": "gpt",
"value": "import string\nimport random\n\ndef generate_password():\n chars = string.ascii_letters + string.digits\n return ''.join(random.choice(chars) for ... |
[
{
"from": "human",
"value": "Generate a list using a while loop in Python and appends the current number to the list."
},
{
"from": "gpt",
"value": "my_list = []\n\nnum = 0\n\nwhile num < 10:\n my_list.append(num)\n num += 1\n\nprint(my_list)"
}
] |
[
{
"from": "human",
"value": "Write a Python program to query Twitter to get the most recent tweets from a user."
},
{
"from": "gpt",
"value": "import tweepy\n\n# Authenticate to Twitter\nauth = tweepy.OAuthHandler(\"CONSUMER_KEY\", \"CONSUMER_SECRET\")\nauth.set_access_token(\"ACCESS_TOKEN\", \"... |
[
{
"from": "human",
"value": "Create a Python neural network model that takes in a given trajectory of stock prices and predicts the stock price for the next day."
},
{
"from": "gpt",
"value": "import numpy as np\nimport tensorflow as tf\n\ndef create_model():\n model = tf.keras.Sequential([\n... |
[
{
"from": "human",
"value": "Create a way to encrypt a message using a key in Python."
},
{
"from": "gpt",
"value": "import hashlib\n\ndef encrypt(message, key):\n encrypted_msg = \"\"\n for char in message:\n encrypted_msg += chr(ord(char) + ord(key[0]))\n return encrypted_msg\n... |
[
{
"from": "human",
"value": "Create a function in Python that takes two parameters and prints out the larger of them."
},
{
"from": "gpt",
"value": "def printMax(parameter_1, parameter_2):\n if parameter_1 > parameter_2:\n print(parameter_1)\n else:\n print(parameter_2)"
}
] |
[
{
"from": "human",
"value": "Rewrite the following Python code by introducing list comprehensions."
},
{
"from": "gpt",
"value": "even_numbers = [i for i in range(1, 21) if i % 2 == 0]"
}
] |
[
{
"from": "human",
"value": "Develop an algorithm in Python to print Fibonacci series up to a given number."
},
{
"from": "gpt",
"value": "def fibonacci(n): \n a = 0\n b = 1\n if n < 0: \n print(\"Incorrect input\") \n elif n == 0: \n return a \n elif n == 1: \n ... |
[
{
"from": "human",
"value": "Make the following code snippet into a function in Python3 capable of solving Any Sudoku puzzle"
},
{
"from": "gpt",
"value": "def solve_sudoku(board): \n \n # Utility function to find vacant cells \n # Returns a boolean \n def find_vacant_cell(board, l... |
[
{
"from": "human",
"value": "Write a function in Python to calculate the sum of the digits in a given number."
},
{
"from": "gpt",
"value": "def sum_digits(num):\n total = 0\n while num > 0:\n digit = num % 10\n total += digit\n num = num // 10\n return total"
}
] |
[
{
"from": "human",
"value": "Take the list of people below and create a Python dictionary with the names as keys and the ages as values."
},
{
"from": "gpt",
"value": "people_dict = {'John': 20, 'Jane': 40, 'Alex': 18, 'Peter': 45}"
}
] |
[
{
"from": "human",
"value": "Develop a Python program to clearly understand the concept of recursion."
},
{
"from": "gpt",
"value": "# This program is to understand recursion in Python.\n\n# Define a recursive function to calculate the factorial of a number\ndef factorial(n):\n if n == 1:\n ... |
[
{
"from": "human",
"value": "Generate a random 6-digits number in Python."
},
{
"from": "gpt",
"value": "import random\n\nnumber = random.randint(100000, 999999)\nprint(number)"
}
] |
[
{
"from": "human",
"value": "Create a sorting algorithm in Python to sort strings by their length."
},
{
"from": "gpt",
"value": "def sort_by_length(strings):\n for i in range(len(strings) - 1):\n for j in range(i + 1, len(strings)):\n if len(strings[i]) > len(strings[j]):\n... |
[
{
"from": "human",
"value": "Write a Python function to get the maximum and minimum values in a given list."
},
{
"from": "gpt",
"value": "def get_max_min(lst):\n min_value = lst[0]\n max_value = lst[0]\n \n for i in range(1, len(lst)):\n if lst[i] > max_value:\n max_value = lst[i]\n if lst[... |
[
{
"from": "human",
"value": "Create a for loop in Python to iterate over a list of numbers and print only the even numbers."
},
{
"from": "gpt",
"value": "for num in my_list:\n if num % 2 == 0:\n print(num)"
}
] |
[
{
"from": "human",
"value": "Can you suggest a pure python alternative to declaring a Float32 array with numbers from 0 to 10?"
},
{
"from": "gpt",
"value": "myArray = [float(i) for i in range(0,11)]"
}
] |
[
{
"from": "human",
"value": "Construct a neural network model in Python to classify the MNIST data set correctly."
},
{
"from": "gpt",
"value": "import keras\n\n# Input layer\ninput_layer = keras.layers.Input(shape=(784,))\n\n# Hidden layer\nhidden_layer = keras.layers.Dense(128, \n ... |
[
{
"from": "human",
"value": "Create a machine learning classifier in Python for categorizing user input."
},
{
"from": "gpt",
"value": "from sklearn.naive_bayes import MultinomialNB \n\n# Assuming an input string is passed to the function as a parameter\n\ndef classify_string(input_string):\n\n ... |
[
{
"from": "human",
"value": "Implement a algorithm in Python for sorting two large lists A and B. The algorithm should take the first element of list A and compare it with the first element of list B. If it is greater, then it should add the element to the result list and move the pointer of B to the next e... |
[
{
"from": "human",
"value": "Develop a program in Python for finding the longest common subsequence between two strings."
},
{
"from": "gpt",
"value": "def longest_common_subsequence(string1, string2):\n table = [[0]*(len(string2)+1) for _ in range(len(string1)+1)]\n\n for i, x in enumerat... |
[
{
"from": "human",
"value": "Convert a given Python program to a C# program."
},
{
"from": "gpt",
"value": "public int Power(int x, int y)\n{\n if (y == 0)\n {\n return 1;\n }\n else\n {\n return x * Power(x, y - 1);\n }\n}"
}
] |
[
{
"from": "human",
"value": "Rewrite the following code in a different programming language."
},
{
"from": "gpt",
"value": "# Python code\narr = [1, 2, 3, 4, 5]\n\nfor item in arr:\n print(item * 2)"
}
] |
[
{
"from": "human",
"value": "Create a TicTacToe game in Python."
},
{
"from": "gpt",
"value": "class TicTacToe:\n\ndef __init__(self):\n self.board = [['_' for _ in range(3)] \n for _ in range(3)]\n self.turn = 'x'\n \ndef display(self):\n for row in self.board:\n ... |
[
{
"from": "human",
"value": "Create a Python program to store the strings \"Hello\" and \"World\" and print them in the same line."
},
{
"from": "gpt",
"value": "string1 = \"Hello\"\nstring2 = \"World\"\n\nprint(string1 + \" \" + string2)"
}
] |
[
{
"from": "human",
"value": "Use the inputs provided, write Python code to check if two integers are equal."
},
{
"from": "gpt",
"value": "if int(10) == int(10):\n print(\"The two integers are equal\")\nelse:\n print(\"The two integers are not equal\")"
}
] |
[
{
"from": "human",
"value": "Create a Python program for analyzing the sentiment of given text. The program should categorize the text into positive, negative, and neutral sentiments."
},
{
"from": "gpt",
"value": "import nltk\nfrom nltk.tokenize import sent_tokenize\nfrom nltk.classify import N... |
[
{
"from": "human",
"value": "Create a Python program to calculate the average of five numbers entered by a user."
},
{
"from": "gpt",
"value": "nums = []\nfor i in range(5):\n nums.append(int(input(\"Please enter number: \")))\n\n#Calculate average\naverage = sum(nums) / len(nums)\n\n#Print a... |
[
{
"from": "human",
"value": "Write a Python program to generate a Markov chain given a text input."
},
{
"from": "gpt",
"value": "import random\n\ndef generateMarkov(text):\n words = text.split(' ')\n markovChain = {}\n\n for i in range(len(words) - 2):\n current = words[i]\n next = wor... |
[
{
"from": "human",
"value": "Write a Python program to determine if a number provided by the user is prime or not."
},
{
"from": "gpt",
"value": "# Ask the user for a number\nnum = int(input('Enter a number: '))\n\n# Set initial values\nis_prime = True\n\n# Check for prime\nfor i in range(2, num... |
[
{
"from": "human",
"value": "Write a Python program to calculate the difference between the lowest and highest value for an array of integers."
},
{
"from": "gpt",
"value": "def diffHighestLowest(arr):\n lowest = min(arr)\n highest = max(arr)\n return highest - lowest\n\narr = [12, 24, ... |
[
{
"from": "human",
"value": "Rewrite the following code snippet to find prime numbers using Python."
},
{
"from": "gpt",
"value": "def is_prime(num):\n # Iterate from 2 to the square root of the number\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n return ... |
[
{
"from": "human",
"value": "Write a Python program to create a dictionary where the keys are numbers between 1 and 15 (both included) and the values are square of keys."
},
{
"from": "gpt",
"value": "d = {}\n\nfor i in range(1, 16):\n d[i] = i**2\n\nprint(d)"
}
] |
[
{
"from": "human",
"value": "Write a Python program to calculate the sum of all even numbers less than or equal to n."
},
{
"from": "gpt",
"value": "def sum_of_even_numbers(n):\n result = 0\n for i in range(2, n+1, 2):\n result += i\n return result"
}
] |
[
{
"from": "human",
"value": "Create a Python script to calculate the Fibonacci numbers up to a given number."
},
{
"from": "gpt",
"value": "def Fibonacci(n): \n\tif n==0: \n\t\treturn 0\n\tif n==1: \n\t\treturn 1\n\telse: \n\t\treturn Fibonacci(n-1)+Fibonacci(n-2)"
}
] |
[
{
"from": "human",
"value": "Write a Python program to calculate the total cost of a shopping cart. The program should consider the item prices, quantity, shipping cost, and any applicable taxes."
},
{
"from": "gpt",
"value": "items = [\n {\"name\": \"widget\", \"price\": 10, \"quantity\": 5 },\... |
[
{
"from": "human",
"value": "In Python, create a function to find the maximum value within a nested dictionary."
},
{
"from": "gpt",
"value": "def findMaxValue(dict):\n max_val = None\n for key, value in dict.items():\n if isinstance(value, dict):\n max_val = max(findMaxV... |
[
{
"from": "human",
"value": "Write a function in Python that returns an object of the following time and date: Sunday March 7 5:30 PM."
},
{
"from": "gpt",
"value": "from datetime import datetime\n\ndef get_date_time():\n dt = datetime(year=2021, month=3, day=7, hour=17, minute=30)\n retur... |
[
{
"from": "human",
"value": "Generate a Python program to perform matrix multiplication on two given matrices."
},
{
"from": "gpt",
"value": "def matrix_multiplication(A, B): \n rows_A = len(A) \n cols_A = len(A[0]) \n rows_B = len(B) \n cols_B = len(B[0]) \n result = [[0 for... |
[
{
"from": "human",
"value": "Write a Python script to read an array from the user and then determine the mean and median of the array."
},
{
"from": "gpt",
"value": "def mean_median(arr): \n arr_sum = 0 \n for i in range(len(arr)): \n arr_sum += arr[i] \n \n mean =... |
[
{
"from": "human",
"value": "Create an algorithm in Python to check whether an array has even or odd number of elements."
},
{
"from": "gpt",
"value": "def is_array_even(arr): \n if len(arr)%2 == 0:\n return True\n else:\n return False"
}
] |
[
{
"from": "human",
"value": "Implement a Python function to calculate the Gini coefficient of a given dataset."
},
{
"from": "gpt",
"value": "def gini(x):\n \"\"\"Calculate Gini Coefficient of a given dataset.\"\"\"\n # calculate the frequency of each item in x\n x_value_counts = x.valu... |
[
{
"from": "human",
"value": "Generate a neural network model with TensorFlow and Python for classifying hand-written digits from the MNIST dataset."
},
{
"from": "gpt",
"value": "import tensorflow as tf\n\n# Import MNIST data\nfrom tensorflow.examples.tutorials.mnist import input_data\nmnist = i... |
[
{
"from": "human",
"value": "Write a function to generate a prime number sequence using Python."
},
{
"from": "gpt",
"value": "def generate_prime_numbers(n): \n primes = [True for i in range(n+ 1)] \n p = 2\n while (p * p <= n): \n if (primes[p] == True): \n ... |
[
{
"from": "human",
"value": "Write a Python program that removes duplicates from a list."
},
{
"from": "gpt",
"value": "def remove_duplicates(my_list):\n return list(dict.fromkeys(my_list))\n\nmy_list = [1, 2, 3, 4, 3, 2, 1]\n\nprint(remove_duplicates(my_list)) # output [1, 2, 3, 4]"
}
] |
[
{
"from": "human",
"value": "Generate a Python script to sort the given list of words."
},
{
"from": "gpt",
"value": "# function to sort the given list of words\ndef sort_words(words):\n # sort the list of words in alphabetical order\n words.sort()\n\n # print the sorted list of words\n... |
[
{
"from": "human",
"value": "Generate a function for calculating the average of a list of numbers in Python."
},
{
"from": "gpt",
"value": "def avg_list(lst):\n sum = 0\n count = 0\n for i in lst:\n sum += i\n count += 1\n avg = sum / count\n return avg"
}
] |
[
{
"from": "human",
"value": "Generate a Python program that compares two binary trees to check if they are similar."
},
{
"from": "gpt",
"value": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef are_similar(root1, root... |
[
{
"from": "human",
"value": "Create a program for solving a quadratic equation in Python."
},
{
"from": "gpt",
"value": "import math\n \ndef solveQuadratic(a, b, c): \n discriminant = (b**2) - (4*a*c);\n \n # If discriminant is negative there are no real roots.\n if (discriminant < ... |
[
{
"from": "human",
"value": "Construct a Python code for adding two matrices."
},
{
"from": "gpt",
"value": "def add_matrix(matrix1, matrix2):\n if len(matrix1) != len(matrix2):\n return 'Matrices not compatible'\n if len(matrix1[0]) != len(matrix2[0]):\n return 'Matrices not... |
[
{
"from": "human",
"value": "Generate a Python program which takes a string as input and prints all of its substrings in order from longest to shortest length."
},
{
"from": "gpt",
"value": "def substring_in_order(string): \n result = [] \n n = len(string) \n for l in range(n, 0, -1): \... |
[
{
"from": "human",
"value": "Generate a Python function which takes an array and a value and returns the index at which this value is present in the array."
},
{
"from": "gpt",
"value": "def find_index(arr, x):\n for i in range(len(arr)):\n if arr[i] == x:\n return i\n re... |
[
{
"from": "human",
"value": "Develop a Python program to find the common elements in two lists."
},
{
"from": "gpt",
"value": "common_elements = [] \n \n# using loop \nfor i in [3, 9, 15, 21, 27]: \n for j in [21, 7, 13, 29, 31]: \n if i == j: \n common_elements.append(i)... |
[
{
"from": "human",
"value": "Create a Python program that takes in two strings and returns an integer indicating the number of common substrings between the two strings."
},
{
"from": "gpt",
"value": "def num_common_substrings(s1, s2):\n count = 0\n for i in range(len(s1)):\n for j ... |
[
{
"from": "human",
"value": "Generate a Python program to convert a string to its lowercase version."
},
{
"from": "gpt",
"value": "def str_to_lower(string):\n new_string = \"\"\n\n for char in string:\n new_string += char.lower()\n\n return new_string"
}
] |
[
{
"from": "human",
"value": "Can you generate a function in Python that shuffles a given list?"
},
{
"from": "gpt",
"value": "import random\n\ndef shuffle_list(list): \n # Initialize the random number generator\n random.seed()\n\n # Shuffle the list\n random.shuffle(list) \n\n # R... |
[
{
"from": "human",
"value": "Write a Python function to validate an a list of emails. The function should return a boolean indicating whether a given email address is valid."
},
{
"from": "gpt",
"value": "def validate_mail_list(mail_list):\n for mail in mail_list:\n if not re.match(\"[... |
[
{
"from": "human",
"value": "Create a Python script that will perform several simple math operations. The script should accept two integers as inputs and output the results of the following operations: addition, subtraction, multiplication, division, and modulo."
},
{
"from": "gpt",
"value": "in... |
[
{
"from": "human",
"value": "Create a Python program to perform sentiment analysis on product reviews. The program should use natural language processing techniques like tokenization and n-grams to generate features for sentiment analysis and use a classification model to assign sentiments to the reviews."
... |
[
{
"from": "human",
"value": "Write a python program to clean up a list of emails and put them into a new list."
},
{
"from": "gpt",
"value": "original_list = ['bob@example.com', 'alice+bob@cafe.com', 'bob@gmail.com.uk', 'bob+alice@example']\n\nclean_list = []\n\nfor email in original_list:\n ema... |
[
{
"from": "human",
"value": "Generate sample data for a web application using Python's faker library. The output should contain three columns of data: name, email, and age."
},
{
"from": "gpt",
"value": "from faker import Faker\n\nfake = Faker()\nfor _ in range(10):\n print(fake.name(), fake.ema... |
[
{
"from": "human",
"value": "Create a Python algorithm to classify positive and negative sentiment in tweets."
},
{
"from": "gpt",
"value": "def sentiment_analysis(tweets):\n # Initialize a list to store the result \n results = [] \n\n # Iterate through each tweet\n for tweet in twee... |
[
{
"from": "human",
"value": "Parse the given URL and print out the protocol, domain name, and path using Python."
},
{
"from": "gpt",
"value": "import urllib.parse\n\nurl = 'https://www.example.com/path/to/file'\nparsed_url = urllib.parse.urlparse(url)\n\n# Get the protocol\nprotocol = parsed_ur... |
[
{
"from": "human",
"value": "Write a recursive Python function to generate Fibonacci numbers."
},
{
"from": "gpt",
"value": "def fibonacci(n):\n if n == 1 or n == 2:\n return 1\n else:\n return fibonacci(n - 1) + fibonacci(n - 2)\n \nprint(fibonacci(10))"
}
] |
[
{
"from": "human",
"value": "Create a Kubernetes pod setup that publishes a tweet every 5 minutes."
},
{
"from": "gpt",
"value": "apiVersion: v1\nkind: Pod\nmetadata:\n name: tweet-publisher\nspec:\n containers:\n - name: tweet-publisher\n image: <INSERT_PUBLIC_PULLABLE_IMAGE_PATH_HERE... |
[
{
"from": "human",
"value": "Write a code to generate a two-dimensional array with zeros shapes in Python"
},
{
"from": "gpt",
"value": "\"\"\"\nWrite a code to generate a two-dimensional array with zeros shapes in Python\n\"\"\"\n\ndef generate_zeros_array(row,col):\n return [[0] * col for _... |
[
{
"from": "human",
"value": "Write a Python code to create a dictionary which contains a data structrue in the form of [x:x^2] where x is the key and x^2 is the value."
},
{
"from": "gpt",
"value": "numbers = [1, 2, 3, 4, 5] \n\ndict_numbers = {num: num**2 for num in numbers}\nprint(dict_numbers... |
[
{
"from": "human",
"value": "Create a Python script to print the numbers from 1 to 50, but for multiples of 3 print \"Fizz\" instead of the number, for multiples of 5 print \"Buzz\" instead of the number and for multiples of both 3 and 5 print \"FizzBuzz\"."
},
{
"from": "gpt",
"value": "for i i... |
[
{
"from": "human",
"value": "Create a Python program to calculate the square root of a user-defined positive number."
},
{
"from": "gpt",
"value": "import math\n\nn = 100\n\n#Calculate the square root of a number\nsquare_root = math.sqrt(n)\n\nprint(f'Square root of {n} is {square_root}')"
}
] |
[
{
"from": "human",
"value": "Create a Python class called Rectangle to represent a two-dimensional rectangle with a length and width."
},
{
"from": "gpt",
"value": "class Rectangle:\n def __init__(self, length, width):\n self.length = length\n self.width = width\n\n def area(... |
[
{
"from": "human",
"value": "Create a data visualization dashboard in Python using Matplotlib."
},
{
"from": "gpt",
"value": "import matplotlib\nimport matplotlib.pyplot as plt\n\n# Generate the data for the dashboard\nx = [1,2,3,4,5]\ny = [10,25,30,50,80]\n\n# Create the figure and set the size... |
[
{
"from": "human",
"value": "Edit the following python code to prompt the user to enter the value of radius to calculate the area of a circle."
},
{
"from": "gpt",
"value": "# Calculate area of a circle\n\nPi = 3.14\n\n# Get radius from user\nradius = float(input(\"Please enter the radius of the... |
[
{
"from": "human",
"value": "Create a Python algorithm to identify the longest word in a sentence."
},
{
"from": "gpt",
"value": "def find_longest_word(sentence):\n words = sentence.split()\n # initialise longest_word variable with 0\n longest_word = 0\n for word in words:\n i... |
[
{
"from": "human",
"value": "Write a Python script that can convert degrees Fahrenheit to degrees Celsius."
},
{
"from": "gpt",
"value": "def FahrenheitToCelsius(temp_fahrenheit):\n temp_celsius = (temp_fahrenheit - 32) * 5/9\n return temp_celsius"
}
] |
[
{
"from": "human",
"value": "Generate a Python function that checks if a given number is an Armstrong number."
},
{
"from": "gpt",
"value": "def is_armstrong_number(num): \n n = len(str(num)) \n # initialize sum \n temp = num \n sum_of_digits = 0\n \n # find sum of nth power ... |
[
{
"from": "human",
"value": "Write a code in Python to print the following pattern:"
},
{
"from": "gpt",
"value": "for i in range(5):\n for j in range(i+1):\n print(\"*\", end=\"\")\n print(\"\")\n\nfor i in range(5, 0, -1):\n for j in range(i):\n print(\"*\", end=\"\")\n ... |
[
{
"from": "human",
"value": "Program a web scraper in Python to extract the latest stock prices from specific websites."
},
{
"from": "gpt",
"value": "import requests\nfrom bs4 import BeautifulSoup\n\n# input\nstocks = [\"AAPL stocks\", \"MSFT stocks\", \"FB stocks\", \"GOOG stocks\"]\n\n# proce... |
[
{
"from": "human",
"value": "The code provides Python wrappers around TensorFlow ops for decoding LibSVM input to tensors. To use it, call the `decode_libsvm` function with the following arguments: `input` (a `Tensor` of type `string`), `num_features` (an `int` that is `>= 1`), `dtype` (an optional `tf.DTyp... |
[
{
"from": "human",
"value": "Write a Python program to compute the sum of the values of a given dictionary"
},
{
"from": "gpt",
"value": "def dict_sum(dict):\n sum = 0\n for key, value in dict.items():\n sum += value\n return sum"
}
] |
[
{
"from": "human",
"value": "Create a REST API in Python that can be used to delete an item from a list."
},
{
"from": "gpt",
"value": "from flask import Flask, request\nimport json\n\napp = Flask(__name__)\nitems = [\"Apple\", \"Banana\", \"Orange\"]\n\n@app.route('/items', methods=[\"GET\"])\n... |
End of preview. Expand in Data Studio
No dataset card yet
- Downloads last month
- 31