id stringlengths 16 16 | language stringclasses 3
values | category stringclasses 38
values | question stringlengths 2 1.96k | answer stringlengths 1 1.46k | messages listlengths 2 2 | teacher stringclasses 5
values | batch stringclasses 20
values | source stringclasses 677
values | used_in_chat stringclasses 3
values | tokens int64 8 849 |
|---|---|---|---|---|---|---|---|---|---|---|
f90afc28f1e2f182 | en | code_python | factorial with a loop please, need it for homework | This program computes the factorial of a number with a simple loop.
```python
# factorial with a loop
n = int(input("Number: "))
result = 1
for i in range(2, n + 1):
result = result * i
print(f"{n}! = {result}")
```
Save it as factorial.py and run it with "python3 factorial.py". For the input 6 it prints "6! = 720"... | [
{
"role": "user",
"content": "factorial with a loop please, need it for homework"
},
{
"role": "assistant",
"content": "This program computes the factorial of a number with a simple loop.\n```python\n# factorial with a loop\nn = int(input(\"Number: \"))\nresult = 1\nfor i in range(2, n + 1):\n ... | glm-5.3-flash | qa-v1 | train | 120 | |
75d35ca1c596a431 | en | code_python | python script to get the sum and average of a list of numbers pls | This script reads numbers separated by spaces and prints their sum and average.
```python
# sum and average of the numbers you type
line = input("Numbers separated by spaces: ")
nums = [float(x) for x in line.split()]
total = sum(nums)
print("Sum:", total)
print("Average:", total / len(nums))
```
With the input 4 8 15 ... | [
{
"role": "user",
"content": "python script to get the sum and average of a list of numbers pls"
},
{
"role": "assistant",
"content": "This script reads numbers separated by spaces and prints their sum and average.\n```python\n# sum and average of the numbers you type\nline = input(\"Numbers sep... | glm-5.3-flash | qa-v1 | train | 131 | |
4c6e262296ee5356 | en | code_python | python code that writes a few lines to a file and reads them back pls | This program writes three lines to notes.txt and then prints the file back out.
```python
# writes a few lines to a file, then reads them back
with open("notes.txt", "w") as f:
f.write("first line\n")
f.write("second line\n")
f.write("third line\n")
with open("notes.txt") as f:
print(f.read())
```
Save... | [
{
"role": "user",
"content": "python code that writes a few lines to a file and reads them back pls"
},
{
"role": "assistant",
"content": "This program writes three lines to notes.txt and then prints the file back out.\n```python\n# writes a few lines to a file, then reads them back\nwith open(\... | glm-5.3-flash | qa-v1 | train | 137 | |
1d54c092100b4f53 | en | code_python | simple Dog class with bark method python | This program makes a Dog object and makes it bark.
```python
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
print(f"{self.name} says woof!")
dog = Dog("Rex")
dog.bark()
```
Run it and it prints Rex says woof! | [
{
"role": "user",
"content": "simple Dog class with bark method python"
},
{
"role": "assistant",
"content": "This program makes a Dog object and makes it bark.\n```python\nclass Dog:\n def __init__(self, name):\n self.name = name\n\n def bark(self):\n print(f\"{self.name} sa... | beam-free | qa-v1 | train | 85 | |
18d5a572e0cb8783 | en | code_python | hey, can u write code that checks if two words are anagrams | This program asks for two words and checks whether they are anagrams.
```python
# check if two words are anagrams
word1 = input("First word: ")
word2 = input("Second word: ")
# compare the sorted letters, ignoring case
if sorted(word1.lower()) == sorted(word2.lower()):
print("Yes, those are anagrams.")
else:
p... | [
{
"role": "user",
"content": "hey, can u write code that checks if two words are anagrams"
},
{
"role": "assistant",
"content": "This program asks for two words and checks whether they are anagrams.\n```python\n# check if two words are anagrams\nword1 = input(\"First word: \")\nword2 = input(\"S... | glm-5.3-flash | qa-v1 | train | 153 | |
1e8a4b1bf3d5799a | en | code_python | how do i print the even numbers from 1 to 20 in python | This program prints the even numbers from 2 to 20 using a range with a step of 2.
```python
# start at 2, step by 2
for n in range(2, 21, 2):
print(n, end=" ")
print()
```
Run it with "python3 evens.py". It prints 2 4 6 8 10 12 14 16 18 20 on one line. | [
{
"role": "user",
"content": "how do i print the even numbers from 1 to 20 in python"
},
{
"role": "assistant",
"content": "This program prints the even numbers from 2 to 20 using a range with a step of 2.\n```python\n# start at 2, step by 2\nfor n in range(2, 21, 2):\n print(n, end=\" \")\np... | glm-5.3-flash | qa-v1 | train | 123 | |
81aa3e7363dbc916 | en | code_python | make python print a triangle of stars, i pick how many rows | It prints a triangle of stars with one more star on each line, for as many rows as you ask for.
```python
# a triangle of stars, one more star per line
rows = int(input("how many rows: "))
for i in range(1, rows + 1):
print("*" * i)
```
Run it with "python3 stars.py" and enter the number of rows. With 5 it prints... | [
{
"role": "user",
"content": "make python print a triangle of stars, i pick how many rows"
},
{
"role": "assistant",
"content": "It prints a triangle of stars with one more star on each line, for as many rows as you ask for.\n\n```python\n# a triangle of stars, one more star per line\nrows = int... | hy4-preview | qa-v1 | train | 120 | |
0ba9d248fccc1d14 | en | code_python | factorial with a for loop in python, nothing fancy | This program computes the factorial of a number with a loop.
```python
n = int(input("Factorial of which number? "))
result = 1
# multiply 1 by every number up to n
for i in range(2, n + 1):
result = result * i
print(f"{n}! = {result}")
```
Save it as fact.py and run it with "python3 fact.py". With "5" it prints "5... | [
{
"role": "user",
"content": "factorial with a for loop in python, nothing fancy"
},
{
"role": "assistant",
"content": "This program computes the factorial of a number with a loop.\n```python\nn = int(input(\"Factorial of which number? \"))\nresult = 1\n# multiply 1 by every number up to n\nfor ... | glm-5.3-flash | qa-v1 | train | 128 | |
5d344fc04c0e2d6c | en | code_python | write a password strength checker in python | This program gives a password one point each for length, mixed case, a digit and a symbol, then rates it from very weak to very strong.
```python
# rate how strong a password is
password = input("Password: ")
score = 0
if len(password) >= 8:
score += 1
if any(c.islower() for c in password) and any(c.isupper() for... | [
{
"role": "user",
"content": "write a password strength checker in python"
},
{
"role": "assistant",
"content": "This program gives a password one point each for length, mixed case, a digit and a symbol, then rates it from very weak to very strong.\n\n```python\n# rate how strong a password is\n... | hy4-preview | qa-v1 | train | 235 | |
db5b135e2a23aedd | en | code_python | build a little number guessing game in python, it should read my guesses with input() | This game has a secret number from 1 to 10 and asks for guesses until you find it.
```python
secret = 7 # the number to guess
tries = 0
while True:
guess = int(input("Guess a number from 1 to 10: "))
tries += 1
if guess < secret:
print("Too low.")
elif guess > secret:
print("Too high."... | [
{
"role": "user",
"content": "build a little number guessing game in python, it should read my guesses with input()"
},
{
"role": "assistant",
"content": "This game has a secret number from 1 to 10 and asks for guesses until you find it.\n```python\nsecret = 7 # the number to guess\ntries = 0\n... | glm-5.3-flash | qa-v1 | train | 187 | |
5bd090920c8c1f08 | en | code_python | hey can u make a python thing that converts celsius to fahrenheit, it should ask me for the temp | This program asks for a temperature in Celsius and prints it in Fahrenheit.
```python
# ask for a temperature in celsius
celsius = float(input("Celsius: "))
fahrenheit = celsius * 9 / 5 + 32
print(f"{celsius} degrees Celsius is {fahrenheit:.1f} degrees Fahrenheit")
```
Save it as celsius.py and run it with "python3 ... | [
{
"role": "user",
"content": "hey can u make a python thing that converts celsius to fahrenheit, it should ask me for the temp"
},
{
"role": "assistant",
"content": "This program asks for a temperature in Celsius and prints it in Fahrenheit.\n\n```python\n# ask for a temperature in celsius\ncels... | hy4-preview | qa-v1 | train | 146 | |
577bb421d3b3b1e0 | en | code_python | code that writes few lines to a file then reads them back in python | This writes three lines into notes.txt and then reads the file back and prints it.
```python
lines = ["first line", "second line", "third line"]
# write the lines to a file
with open("notes.txt", "w") as f:
for line in lines:
f.write(line + "\n")
# read them back and print
with open("notes.txt") as f:
... | [
{
"role": "user",
"content": "code that writes few lines to a file then reads them back in python"
},
{
"role": "assistant",
"content": "This writes three lines into notes.txt and then reads the file back and prints it.\n\n```python\nlines = [\"first line\", \"second line\", \"third line\"]\n\n#... | hy4-preview | qa-v1 | train | 166 | |
c8284c644073a301 | en | code_python | python factorial with recursion pls | This program prints the factorial of a number using recursion.
```python
def factorial(n):
# base case
if n <= 1:
return 1
return n * factorial(n - 1)
n = int(input("Number: "))
print(f"{n}! = {factorial(n)}")
```
Run it with "python3 factorial.py" and type 6. It prints "6! = 720". | [
{
"role": "user",
"content": "python factorial with recursion pls"
},
{
"role": "assistant",
"content": "This program prints the factorial of a number using recursion.\n```python\ndef factorial(n):\n # base case\n if n <= 1:\n return 1\n return n * factorial(n - 1)\n\nn = int(inp... | glm-5.3-flash | qa-v1 | train | 111 | |
9fa757932d80b368 | en | code_python | hey can u make a python thing that prints a temperature table from 0 to 100 celsius | This prints a Celsius to Fahrenheit table from 0 to 100 in steps of 10.
```python
# Celsius to Fahrenheit table from 0 to 100
print("C F")
for c in range(0, 101, 10):
f = c * 9 / 5 + 32
print(c, round(f, 1))
```
Save it as temps.py and run it with "python3 temps.py". It starts with 0 C = 32.0 F and ends ... | [
{
"role": "user",
"content": "hey can u make a python thing that prints a temperature table from 0 to 100 celsius"
},
{
"role": "assistant",
"content": "This prints a Celsius to Fahrenheit table from 0 to 100 in steps of 10.\n\n```python\n# Celsius to Fahrenheit table from 0 to 100\nprint(\"C ... | hy4-preview | qa-v1 | train | 165 | |
6a8cfa7f07ccae4f | en | code_python | python script that checks if a word is a palindrome? | This program reads a word and tells you whether it reads the same backwards.
```python
word = input("Word: ").strip().lower()
if word == word[::-1]:
print("Yes, it is a palindrome.")
else:
print("No, it is not a palindrome.")
```
Save it as palindrome.py and run it with python3 palindrome.py. Typing Level pri... | [
{
"role": "user",
"content": "python script that checks if a word is a palindrome?"
},
{
"role": "assistant",
"content": "This program reads a word and tells you whether it reads the same backwards.\n\n```python\nword = input(\"Word: \").strip().lower()\nif word == word[::-1]:\n print(\"Yes, ... | hy4-preview | qa-v1 | train | 101 | |
163d4caabc70af2f | en | code_python | hey can u make me a todo list thing in python, just in memory nothing fancy | This program keeps a to-do list in memory, with a small menu to add, show and remove tasks.
```python
todo = [] # lives in memory only
while True:
print("1) add 2) show 3) remove 4) quit")
choice = input("pick: ")
if choice == "1":
todo.append(input("task: "))
elif choice == "2":
f... | [
{
"role": "user",
"content": "hey can u make me a todo list thing in python, just in memory nothing fancy"
},
{
"role": "assistant",
"content": "This program keeps a to-do list in memory, with a small menu to add, show and remove tasks.\n\n```python\ntodo = [] # lives in memory only\n\nwhile Tr... | hy4-preview | qa-v1 | train | 250 | |
cb8c9d951914df95 | en | code_python | can u write a factorial function using recursion in python | This program asks for a number and prints its factorial using recursion.
```python
def factorial(n):
# base case: 0! and 1! are 1
if n <= 1:
return 1
return n * factorial(n - 1)
n = int(input("Enter a number: "))
print(f"{n}! = {factorial(n)}")
```
Run it with "python3 factorial.py". Typing 5 print... | [
{
"role": "user",
"content": "can u write a factorial function using recursion in python"
},
{
"role": "assistant",
"content": "This program asks for a number and prints its factorial using recursion.\n```python\ndef factorial(n):\n # base case: 0! and 1! are 1\n if n <= 1:\n return... | glm-5.3-flash | qa-v1 | train | 128 | |
171692895bcb1036 | en | code_python | print just the even numbers from 1 to 20 in python ty | This program prints the even numbers from 1 to 20.
```python
for n in range(2, 21, 2):
print(n)
```
Run it with "python3 evens.py". It prints 2, 4, 6, 8, 10, 12, 14, 16, 18 and 20, one per line. | [
{
"role": "user",
"content": "print just the even numbers from 1 to 20 in python ty"
},
{
"role": "assistant",
"content": "This program prints the even numbers from 1 to 20.\n\n```python\nfor n in range(2, 21, 2):\n print(n)\n```\n\nRun it with \"python3 evens.py\". It prints 2, 4, 6, 8, 10, ... | hy4-preview | qa-v1 | train | 106 | |
4e259b8e2bcb101a | en | code_python | can u print all the prime numbers up to 50 in python | This program prints every prime number up to 50.
```python
# check every number from 2 to 50 for divisors
for n in range(2, 51):
is_prime = True
for d in range(2, n):
if n % d == 0:
is_prime = False
break
if is_prime:
print(n, end=" ")
print()
```
Run it with python3 ... | [
{
"role": "user",
"content": "can u print all the prime numbers up to 50 in python"
},
{
"role": "assistant",
"content": "This program prints every prime number up to 50.\n```python\n# check every number from 2 to 50 for divisors\nfor n in range(2, 51):\n is_prime = True\n for d in range(2... | glm-5.3-flash | qa-v1 | train | 165 | |
6dbfb3b8eec17922 | en | code_python | squares of 1 to 10 with a list comprehension | This program makes a list of the squares of 1 to 10.
```python
squares = [i * i for i in range(1, 11)]
print(squares)
```
Run it with Python 3. It prints [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]. | [
{
"role": "user",
"content": "squares of 1 to 10 with a list comprehension"
},
{
"role": "assistant",
"content": "This program makes a list of the squares of 1 to 10.\n```python\nsquares = [i * i for i in range(1, 11)]\nprint(squares)\n```\nRun it with Python 3. It prints [1, 4, 9, 16, 25, 36, 4... | beam-free | qa-v1 | train | 107 | |
1066b19e39a4e3c5 | en | code_python | list all primse up to 50 in python | This program lists all prime numbers up to 50.
```python
primes = []
for n in range(2, 51):
if all(n % d != 0 for d in range(2, int(n ** 0.5) + 1)):
primes.append(n)
print(primes)
```
Run it with Python 3. It prints [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]. | [
{
"role": "user",
"content": "list all primse up to 50 in python"
},
{
"role": "assistant",
"content": "This program lists all prime numbers up to 50.\n```python\nprimes = []\nfor n in range(2, 51):\n if all(n % d != 0 for d in range(2, int(n ** 0.5) + 1)):\n primes.append(n)\nprint(pr... | beam-free | qa-v1 | train | 154 | |
39cd2586b961ab81 | en | code_python | can you write a program that writes a few lines to a file and then reads them back | This one writes three lines to a file called notes.txt and then reads the file back and prints it.
```python
# write three lines to a file, then read them back
with open("notes.txt", "w") as f:
f.write("hello\n")
f.write("this is a test\n")
f.write("goodbye\n")
with open("notes.txt") as f:
print(f.read... | [
{
"role": "user",
"content": "can you write a program that writes a few lines to a file and then reads them back"
},
{
"role": "assistant",
"content": "This one writes three lines to a file called notes.txt and then reads the file back and prints it.\n```python\n# write three lines to a file, th... | glm-5.3-flash | qa-v1 | validation | 140 | |
c7a2bb181c7fb8c7 | en | code_python | need a bubble sort in python for a list of numbers | This program sorts a list of numbers with bubble sort and prints the result.
```python
# sort a list with bubble sort
numbers = [5, 1, 4, 2, 8]
for i in range(len(numbers)):
for j in range(len(numbers) - 1 - i):
if numbers[j] > numbers[j + 1]:
numbers[j], numbers[j + 1] = numbers[j + 1], numbers... | [
{
"role": "user",
"content": "need a bubble sort in python for a list of numbers"
},
{
"role": "assistant",
"content": "This program sorts a list of numbers with bubble sort and prints the result.\n```python\n# sort a list with bubble sort\nnumbers = [5, 1, 4, 2, 8]\nfor i in range(len(numbers))... | glm-5.3-flash | qa-v1 | train | 151 | |
9c7c667d861ac62c | en | code_python | can you bubble sort a list for me in python | This program bubble sorts a small list of numbers from smallest to largest.
```python
# bubble sort a list
numbers = [5, 1, 4, 2, 8]
n = len(numbers)
for i in range(n):
for j in range(n - 1 - i):
if numbers[j] > numbers[j + 1]:
numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j]
print(number... | [
{
"role": "user",
"content": "can you bubble sort a list for me in python"
},
{
"role": "assistant",
"content": "This program bubble sorts a small list of numbers from smallest to largest.\n```python\n# bubble sort a list\nnumbers = [5, 1, 4, 2, 8]\nn = len(numbers)\nfor i in range(n):\n for ... | glm-5.3-flash | qa-v1 | train | 149 | |
e52ca9bbca32496d | en | code_python | can u write a dog class in python with a bark method | This program defines a Dog class and makes one dog bark.
```python
# a simple Dog class with a bark method
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
print(self.name, "says Woof!")
my_dog = Dog("Rex")
my_dog.bark()
```
Save it as dog.py and run it with "python3 dog.p... | [
{
"role": "user",
"content": "can u write a dog class in python with a bark method"
},
{
"role": "assistant",
"content": "This program defines a Dog class and makes one dog bark.\n```python\n# a simple Dog class with a bark method\nclass Dog:\n def __init__(self, name):\n self.name = n... | glm-5.3-flash | qa-v1 | validation | 119 | |
02fe945995c1c4b8 | en | code_python | code me a password strength checker | This program scores a password from 0 to 4 for length, digits, capital letters and symbols.
```python
# check how strong a password is
password = input("Type a password: ")
has_digit = False
has_upper = False
has_symbol = False
for c in password:
if c.isdigit():
has_digit = True
if c.isupper():
... | [
{
"role": "user",
"content": "code me a password strength checker"
},
{
"role": "assistant",
"content": "This program scores a password from 0 to 4 for length, digits, capital letters and symbols.\n```python\n# check how strong a password is\npassword = input(\"Type a password: \")\nhas_digit = ... | glm-5.3-flash | qa-v1 | train | 241 | |
f696e14c9cf1863f | en | code_python | make me a number guessing game where i type the guesses | The program picks a number from 1 to 20 and gives you 6 tries, with a hint after each guess.
```python
import random
secret = random.randint(1, 20)
print("Guess a number from 1 to 20. You get 6 tries.")
for attempt in range(6):
guess = int(input("Your guess: "))
if guess == secret:
print("Correct afte... | [
{
"role": "user",
"content": "make me a number guessing game where i type the guesses"
},
{
"role": "assistant",
"content": "The program picks a number from 1 to 20 and gives you 6 tries, with a hint after each guess.\n```python\nimport random\n\nsecret = random.randint(1, 20)\nprint(\"Guess a n... | hy4-preview | qa-v1 | train | 201 | |
1ed584e3c6bde57e | en | code_python | write a python program that checks if two words are anagrams | This program asks for two words and prints whether they are anagrams.
```python
# two words are anagrams if they use the same letters
word1 = input("First word: ").strip().lower()
word2 = input("Second word: ").strip().lower()
if sorted(word1) == sorted(word2):
print("Yes, they are anagrams.")
else:
print("No, ... | [
{
"role": "user",
"content": "write a python program that checks if two words are anagrams"
},
{
"role": "assistant",
"content": "This program asks for two words and prints whether they are anagrams.\n```python\n# two words are anagrams if they use the same letters\nword1 = input(\"First word: \... | glm-5.3-flash | qa-v1 | train | 170 | |
0ef52443995f9934 | en | code_python | how do i bubble sort a list in python? | This program sorts a small list of numbers with bubble sort.
```python
numbers = [5, 2, 9, 1, 7]
# keep swapping neighbors until the list is sorted
for i in range(len(numbers)):
for j in range(len(numbers) - 1 - i):
if numbers[j] > numbers[j + 1]:
numbers[j], numbers[j + 1] = numbers[j + 1], nu... | [
{
"role": "user",
"content": "how do i bubble sort a list in python?"
},
{
"role": "assistant",
"content": "This program sorts a small list of numbers with bubble sort.\n```python\nnumbers = [5, 2, 9, 1, 7]\n\n# keep swapping neighbors until the list is sorted\nfor i in range(len(numbers)):\n ... | glm-5.3-flash | qa-v1 | train | 150 | |
4892b98071d9795d | en | code_python | simple Dog class with a bark method pls | It defines a Dog class that keeps a name and has a bark method that prints that name plus "Woof!".
```python
# a simple Dog class
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
print(self.name + " says Woof!")
rex = Dog("Rex")
rex.bark()
```
Save it as dog.py and run "... | [
{
"role": "user",
"content": "simple Dog class with a bark method pls"
},
{
"role": "assistant",
"content": "It defines a Dog class that keeps a name and has a bark method that prints that name plus \"Woof!\".\n\n```python\n# a simple Dog class\nclass Dog:\n def __init__(self, name):\n ... | hy4-preview | qa-v1 | train | 138 | |
f006e43f70685b17 | en | code_python | convert celsius to fahrenheit python | This program converts a Celsius temperature to Fahrenheit.
```python
c = float(input("Celsius: "))
print(c * 9 / 5 + 32)
```
Run it, type 0, and it prints 32.0. | [
{
"role": "user",
"content": "convert celsius to fahrenheit python"
},
{
"role": "assistant",
"content": "This program converts a Celsius temperature to Fahrenheit.\n```python\nc = float(input(\"Celsius: \"))\nprint(c * 9 / 5 + 32)\n```\nRun it, type 0, and it prints 32.0."
}
] | beam-free | qa-v1 | train | 66 | |
06039d2144c19f0d | en | code_python | give me a python program that finds the longest word in a sentence | This reads a sentence and prints its longest word.
```python
# find the longest word in a sentence
sentence = input("Sentence: ")
words = sentence.split()
longest = max(words, key=len)
print("Longest word:", longest)
```
Run it with "python3 longest.py" and type a sentence. With "I love programming in Python" it prints... | [
{
"role": "user",
"content": "give me a python program that finds the longest word in a sentence"
},
{
"role": "assistant",
"content": "This reads a sentence and prints its longest word.\n```python\n# find the longest word in a sentence\nsentence = input(\"Sentence: \")\nwords = sentence.split()... | glm-5.3-flash | qa-v1 | train | 117 | |
7ea4aa4b0a823740 | en | code_python | show me the squares of 1 to 10 using a list comprehension | This program builds a list with the squares of 1 to 10 using a list comprehension.
```python
# squares of 1 to 10 with a list comprehension
squares = [n * n for n in range(1, 11)]
print(squares)
```
Save it as squares.py and run it with "python3 squares.py". It prints [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]. | [
{
"role": "user",
"content": "show me the squares of 1 to 10 using a list comprehension"
},
{
"role": "assistant",
"content": "This program builds a list with the squares of 1 to 10 using a list comprehension.\n```python\n# squares of 1 to 10 with a list comprehension\nsquares = [n * n for n in ... | glm-5.3-flash | qa-v1 | train | 136 | |
76a45a8c554339b6 | en | code_python | binary to decimal python pls | This converts a binary string to a decimal number by doubling the running total and adding each digit.
```python
binary = input('Binary number: ')
total = 0
for digit in binary:
total = total * 2 + int(digit)
print(total)
```
Run it and type a binary number when asked. With 101101 it prints 45. | [
{
"role": "user",
"content": "binary to decimal python pls"
},
{
"role": "assistant",
"content": "This converts a binary string to a decimal number by doubling the running total and adding each digit.\n```python\nbinary = input('Binary number: ')\n\ntotal = 0\nfor digit in binary:\n total = t... | hy4-preview | qa-v1 | train | 96 | |
65b1d66b12579322 | en | code_python | write a python program that counts the vowles in a sentence | This program counts how many vowels are in the sentence you type.
```python
# count the vowels in a sentence
sentence = input("Enter a sentence: ")
count = 0
for letter in sentence.lower():
if letter in "aeiou":
count += 1
print("Vowels:", count)
```
Save it as vowels.py and run it with "python3 vowels.py... | [
{
"role": "user",
"content": "write a python program that counts the vowles in a sentence"
},
{
"role": "assistant",
"content": "This program counts how many vowels are in the sentence you type.\n```python\n# count the vowels in a sentence\nsentence = input(\"Enter a sentence: \")\ncount = 0\n\n... | glm-5.3-flash | qa-v1 | train | 132 | |
a17e089878bf2cec | en | code_python | need code that counts how many times each word shows up in a sentence | This program counts how often each word appears in the line you type.
```python
# count how many times each word appears
text = input("type a sentence: ")
counts = {}
for word in text.split():
counts[word] = counts.get(word, 0) + 1
for word, n in counts.items():
print(word, n)
```
With the test sentence it prin... | [
{
"role": "user",
"content": "need code that counts how many times each word shows up in a sentence"
},
{
"role": "assistant",
"content": "This program counts how often each word appears in the line you type.\n```python\n# count how many times each word appears\ntext = input(\"type a sentence: \... | glm-5.3-flash | qa-v1 | train | 119 | |
b7883722558b7ece | en | code_python | hi, need a python snippet that removes duplicates from a list but keeps the order | This snippet keeps only the first copy of each item, so the original order stays.
```python
# remove duplicates but keep the original order
items = [1, 2, 2, 3, 1, 4, 3]
unique = []
for item in items:
if item not in unique:
unique.append(item)
print(unique)
```
Run it with "python3 unique.py" and it prints ... | [
{
"role": "user",
"content": "hi, need a python snippet that removes duplicates from a list but keeps the order"
},
{
"role": "assistant",
"content": "This snippet keeps only the first copy of each item, so the original order stays.\n```python\n# remove duplicates but keep the original order\nit... | glm-5.3-flash | qa-v1 | train | 126 | |
12ad2c3a58fc67a6 | en | code_python | make a triangle of stars in python | This prints a triangle of stars, with one more star on each row.
```python
rows = int(input("How many rows: "))
for i in range(1, rows + 1):
print("*" * i)
```
It asks how many rows you want. With 5 it prints five rows, from one star up to five stars. | [
{
"role": "user",
"content": "make a triangle of stars in python"
},
{
"role": "assistant",
"content": "This prints a triangle of stars, with one more star on each row.\n\n```python\nrows = int(input(\"How many rows: \"))\nfor i in range(1, rows + 1):\n print(\"*\" * i)\n```\n\nIt asks how ma... | hy4-preview | qa-v1 | train | 84 | |
8886fa6c417012d6 | en | code_python | hey, show me bubble sort in python | This sorts a list of numbers with bubble sort and prints the sorted list.
```python
# bubble sort: swap neighbours until sorted
numbers = [5, 1, 4, 2, 8]
for i in range(len(numbers)):
for j in range(len(numbers) - 1 - i):
if numbers[j] > numbers[j + 1]:
numbers[j], numbers[j + 1] = numbers[j + 1... | [
{
"role": "user",
"content": "hey, show me bubble sort in python"
},
{
"role": "assistant",
"content": "This sorts a list of numbers with bubble sort and prints the sorted list.\n```python\n# bubble sort: swap neighbours until sorted\nnumbers = [5, 1, 4, 2, 8]\nfor i in range(len(numbers)):\n ... | glm-5.3-flash | qa-v1 | train | 149 | |
cc8dc86e5931eaad | en | code_python | can u write code to check if a word is a palindrome | This program checks if a word reads the same backwards, ignoring capital letters.
```python
# check if a word is a palindrome
word = input("Type a word: ").lower()
if word == word[::-1]:
print(word, "is a palindrome")
else:
print(word, "is not a palindrome")
```
With the input racecar it prints racecar is a pal... | [
{
"role": "user",
"content": "can u write code to check if a word is a palindrome"
},
{
"role": "assistant",
"content": "This program checks if a word reads the same backwards, ignoring capital letters.\n```python\n# check if a word is a palindrome\nword = input(\"Type a word: \").lower()\nif wo... | glm-5.3-flash | qa-v1 | train | 106 | |
a2f8c3600e42fb3f | en | code_python | hey how do i turn a binary string into a normal decimal number | This reads a string of 0s and 1s and converts it to its decimal value by hand.
```python
b = input("Binary: ").strip()
total = 0
for digit in b:
total = total * 2 + int(digit) # shift left and add the new bit
print(total)
```
Save it as binary.py and run "python3 binary.py". Enter 1011 and it prints 11. | [
{
"role": "user",
"content": "hey how do i turn a binary string into a normal decimal number"
},
{
"role": "assistant",
"content": "This reads a string of 0s and 1s and converts it to its decimal value by hand.\n\n```python\nb = input(\"Binary: \").strip()\ntotal = 0\nfor digit in b:\n total ... | hy4-preview | qa-v1 | train | 119 | |
2fa20af842ea4a06 | en | code_python | make me a little script that reverses a string pls | This program reads a word and prints it backwards.
```python
# flip a string backwards
text = input("Type a word: ")
print("Reversed:", text[::-1])
```
Run it with "python3 reverse.py" and type something like hello. It prints "Reversed: olleh". | [
{
"role": "user",
"content": "make me a little script that reverses a string pls"
},
{
"role": "assistant",
"content": "This program reads a word and prints it backwards.\n```python\n# flip a string backwards\ntext = input(\"Type a word: \")\nprint(\"Reversed:\", text[::-1])\n```\nRun it with \"... | glm-5.3-flash | qa-v1 | train | 80 | |
c48ab6090f44ee85 | en | code_python | count vowels in a sentence python | This program counts the vowels in a sentence you type.
```python
sentence = input("Sentence: ")
count = sum(1 for c in sentence.lower() if c in "aeiou")
print(count)
```
Run it, type Hello World, and it prints 3. | [
{
"role": "user",
"content": "count vowels in a sentence python"
},
{
"role": "assistant",
"content": "This program counts the vowels in a sentence you type.\n```python\nsentence = input(\"Sentence: \")\ncount = sum(1 for c in sentence.lower() if c in \"aeiou\")\nprint(count)\n```\nRun it, type ... | beam-free | qa-v1 | train | 71 | |
cd7203353db2de99 | en | code_python | can u write a bubble sort in python | This program sorts a list from smallest to largest with bubble sort, where big values bubble to the end one swap at a time.
```python
# bubble sort: swap neighbours until sorted
numbers = [5, 1, 4, 2, 8]
n = len(numbers)
for i in range(n - 1):
for j in range(n - 1 - i):
if numbers[j] > numbers[j + 1]:
... | [
{
"role": "user",
"content": "can u write a bubble sort in python"
},
{
"role": "assistant",
"content": "This program sorts a list from smallest to largest with bubble sort, where big values bubble to the end one swap at a time.\n```python\n# bubble sort: swap neighbours until sorted\nnumbers = ... | glm-5.3-flash | qa-v1 | train | 167 | |
920de05fa2f20803 | en | code_python | can you write a little python script that capitalizes every word in a sentence | This reads a sentence and prints it with every word starting with a capital letter.
```python
# capitalize every word in a sentence
sentence = input("Sentence: ")
words = [w[0].upper() + w[1:] for w in sentence.split()]
print(" ".join(words))
```
Run it with "python3 capitalize.py" and type a sentence. With "the quick ... | [
{
"role": "user",
"content": "can you write a little python script that capitalizes every word in a sentence"
},
{
"role": "assistant",
"content": "This reads a sentence and prints it with every word starting with a capital letter.\n```python\n# capitalize every word in a sentence\nsentence = in... | glm-5.3-flash | qa-v1 | train | 116 | |
210d827336eb9824 | en | code_python | can you write a phone book in python using a dictionary so i can look names up | This phone book keeps names and numbers in a dictionary, looks one up and saves the number if the name is new.
```python
phone_book = {"Ana": "555-1234", "Ben": "555-5678"}
name = input("Name to look up: ")
if name in phone_book:
print(name, phone_book[name])
else:
number = input("New contact, what is the num... | [
{
"role": "user",
"content": "can you write a phone book in python using a dictionary so i can look names up"
},
{
"role": "assistant",
"content": "This phone book keeps names and numbers in a dictionary, looks one up and saves the number if the name is new.\n\n```python\nphone_book = {\"Ana\": ... | hy4-preview | qa-v1 | train | 185 | |
ffc6b56556f3d9cf | en | code_python | can you write me a bmi calculator | This program asks for your weight and height and prints your BMI.
```python
# body mass index = weight in kg / height in m squared
weight = float(input("Weight in kg: "))
height = float(input("Height in m: "))
bmi = weight / height ** 2
print("Your BMI is", round(bmi, 1))
```
Save it as bmi.py and run it with "python3 ... | [
{
"role": "user",
"content": "can you write me a bmi calculator"
},
{
"role": "assistant",
"content": "This program asks for your weight and height and prints your BMI.\n```python\n# body mass index = weight in kg / height in m squared\nweight = float(input(\"Weight in kg: \"))\nheight = float(i... | glm-5.3-flash | qa-v1 | train | 135 | |
469c5634dc1713a7 | en | code_python | make me a password strength checker in python | This program asks for a password and rates it from very weak to very strong.
```python
# simple password strength checker
password = input("Enter a password: ")
score = 0
if len(password) >= 8:
score += 1
if any(c.isupper() for c in password):
score += 1
if any(c.islower() for c in password):
score += 1
if... | [
{
"role": "user",
"content": "make me a password strength checker in python"
},
{
"role": "assistant",
"content": "This program asks for a password and rates it from very weak to very strong.\n```python\n# simple password strength checker\npassword = input(\"Enter a password: \")\nscore = 0\n\ni... | glm-5.3-flash | qa-v1 | train | 226 | |
d464594a4fc5999c | en | code_python | i want to count how many times each word shows up in a sentence, python please | This program counts how often each word appears in the sentence you type.
```python
# count how often each word appears
text = input("Type a sentence: ").lower()
counts = {}
for word in text.split():
counts[word] = counts.get(word, 0) + 1
for word, count in counts.items():
print(word, count)
```
Run it with "py... | [
{
"role": "user",
"content": "i want to count how many times each word shows up in a sentence, python please"
},
{
"role": "assistant",
"content": "This program counts how often each word appears in the sentence you type.\n```python\n# count how often each word appears\ntext = input(\"Type a sen... | glm-5.3-flash | qa-v1 | train | 150 | |
0d4044ce2d8b86b8 | en | code_python | make a python script that prints all the prime numbers up to 50 | This program checks every number from 2 to 50 and prints the ones with no divisors.
```python
# check every number from 2 to 50
for n in range(2, 51):
is_prime = True
for d in range(2, n):
if n % d == 0: # found a divisor
is_prime = False
break
if is_prime:
print(n,... | [
{
"role": "user",
"content": "make a python script that prints all the prime numbers up to 50"
},
{
"role": "assistant",
"content": "This program checks every number from 2 to 50 and prints the ones with no divisors.\n```python\n# check every number from 2 to 50\nfor n in range(2, 51):\n is_p... | glm-5.3-flash | qa-v1 | train | 181 | |
fd0d77793e0e1c58 | en | code_python | can u write something that turns a binary string into a decimal number | This program reads a binary string and turns it into a decimal number.
```python
# convert a binary string to a decimal number
binary = input("Enter a binary number: ")
decimal = 0
for digit in binary:
decimal = decimal * 2 + int(digit)
print(decimal)
```
Run it with "python3 binary.py" and type a binary string l... | [
{
"role": "user",
"content": "can u write something that turns a binary string into a decimal number"
},
{
"role": "assistant",
"content": "This program reads a binary string and turns it into a decimal number.\n```python\n# convert a binary string to a decimal number\nbinary = input(\"Enter a b... | glm-5.3-flash | qa-v1 | train | 131 | |
d31fa3c6f6c7032b | en | code_python | how do i capitalize every word in a sentence in python? give me the code | This program reads a sentence and prints it with every word capitalized.
```python
# read a whole sentence
sentence = input("Type a sentence: ")
# capitalize each word and join them back together
caps = " ".join(word.capitalize() for word in sentence.split())
print(caps)
```
Save it as caps.py and run it with "python3 ... | [
{
"role": "user",
"content": "how do i capitalize every word in a sentence in python? give me the code"
},
{
"role": "assistant",
"content": "This program reads a sentence and prints it with every word capitalized.\n```python\n# read a whole sentence\nsentence = input(\"Type a sentence: \")\n# c... | glm-5.3-flash | qa-v1 | train | 118 | |
1bc6e450ef7ae457 | en | code_python | make me a bmi calculator | This program asks for weight and height and prints your BMI.
```python
weight = float(input("Weight in kg: "))
height = float(input("Height in m: "))
bmi = weight / (height * height)
print(f"Your BMI is {bmi:.1f}")
```
Run it with "python3 bmi.py" and enter 70 and 1.75. It prints "Your BMI is 22.9". | [
{
"role": "user",
"content": "make me a bmi calculator"
},
{
"role": "assistant",
"content": "This program asks for weight and height and prints your BMI.\n```python\nweight = float(input(\"Weight in kg: \"))\nheight = float(input(\"Height in m: \"))\nbmi = weight / (height * height)\nprint(f\"Y... | glm-5.3-flash | qa-v1 | train | 109 | |
000f09b43e57b77d | en | code_python | print the even numbers from 1 to 20 in python pls | This script prints every even number from 1 to 20, one per line.
```python
# start at 2 and step by 2 up to 20
for n in range(2, 21, 2):
print(n)
```
Run it with "python3 even.py". It prints 2, 4, 6 and so on up to 20. | [
{
"role": "user",
"content": "print the even numbers from 1 to 20 in python pls"
},
{
"role": "assistant",
"content": "This script prints every even number from 1 to 20, one per line.\n\n```python\n# start at 2 and step by 2 up to 20\nfor n in range(2, 21, 2):\n print(n)\n```\n\nRun it with \... | hy4-preview | qa-v1 | train | 102 | |
a3b451cab20f031a | en | code_python | make me a simple to-do list in pyton, just in memory pls | This program keeps a to-do list in memory and lets you add tasks, show them and remove one by its number.
```python
# simple in-memory to-do list
todos = []
while True:
cmd = input("add/show/done/quit: ").strip().lower()
if cmd == "add":
todos.append(input("Task: "))
elif cmd == "show":
for ... | [
{
"role": "user",
"content": "make me a simple to-do list in pyton, just in memory pls"
},
{
"role": "assistant",
"content": "This program keeps a to-do list in memory and lets you add tasks, show them and remove one by its number.\n```python\n# simple in-memory to-do list\ntodos = []\nwhile Tru... | glm-5.3-flash | qa-v1 | train | 250 | |
d628275a86eb7b63 | en | code_python | write a script that checks if two words are anagrams | This program reads two words and says whether they are anagrams.
```python
# check if two words are anagrams
first = input("First word: ").lower().replace(" ", "")
second = input("Second word: ").lower().replace(" ", "")
if sorted(first) == sorted(second):
print("They are anagrams")
else:
print("They are not a... | [
{
"role": "user",
"content": "write a script that checks if two words are anagrams"
},
{
"role": "assistant",
"content": "This program reads two words and says whether they are anagrams.\n```python\n# check if two words are anagrams\nfirst = input(\"First word: \").lower().replace(\" \", \"\")\n... | glm-5.3-flash | qa-v1 | train | 137 | |
57535cdeb2c42104 | en | code_python | convert celcius to fahrenheit in python pls | This program converts a temperature from Celsius to Fahrenheit.
```python
# Celsius to Fahrenheit
c = input("Celsius: ")
fahrenheit = float(c) * 9 / 5 + 32
print(f"{c} C is {fahrenheit:.1f} F")
```
Run it with python3 convert.py and type a number when it asks. With 25 it prints 25 C is 77.0 F. | [
{
"role": "user",
"content": "convert celcius to fahrenheit in python pls"
},
{
"role": "assistant",
"content": "This program converts a temperature from Celsius to Fahrenheit.\n```python\n# Celsius to Fahrenheit\nc = input(\"Celsius: \")\nfahrenheit = float(c) * 9 / 5 + 32\nprint(f\"{c} C is {f... | glm-5.3-flash | qa-v1 | train | 113 | |
ba4ae05ca051b63c | en | code_python | hey whats the trick for swapping two variables in python | This program swaps two variables without a temp variable, using Python's tuple trick.
```python
# swap two values with a tuple, no temp variable
a = 3
b = 7
print("Before: a =", a, "b =", b)
a, b = b, a
print("After: a =", a, "b =", b)
```
Run it with python3 swap.py. It shows a = 3 b = 7 before the swap and a = 7 b = ... | [
{
"role": "user",
"content": "hey whats the trick for swapping two variables in python"
},
{
"role": "assistant",
"content": "This program swaps two variables without a temp variable, using Python's tuple trick.\n```python\n# swap two values with a tuple, no temp variable\na = 3\nb = 7\nprint(\"... | glm-5.3-flash | qa-v1 | train | 134 | |
32a4bd59472b7a0d | en | code_python | can u write a script that lists all the prime numbers up to 50 | This script checks every number from 2 to 50 and prints the primes.
```python
# list all primes up to 50
primes = []
for n in range(2, 51):
is_prime = True
for d in range(2, n):
if n % d == 0:
is_prime = False
break
if is_prime:
primes.append(n)
print(primes)
```
Run ... | [
{
"role": "user",
"content": "can u write a script that lists all the prime numbers up to 50"
},
{
"role": "assistant",
"content": "This script checks every number from 2 to 50 and prints the primes.\n```python\n# list all primes up to 50\nprimes = []\nfor n in range(2, 51):\n is_prime = True... | glm-5.3-flash | qa-v1 | train | 188 | |
c99436f19fa16249 | en | code_python | fizzbuzz from 1 to 100 in python | This program prints FizzBuzz for the numbers from 1 to 100.
```python
# classic fizzbuzz from 1 to 100
for n in range(1, 101):
if n % 15 == 0:
print("FizzBuzz")
elif n % 3 == 0:
print("Fizz")
elif n % 5 == 0:
print("Buzz")
else:
print(n)
```
Numbers divisible by 3 print F... | [
{
"role": "user",
"content": "fizzbuzz from 1 to 100 in python"
},
{
"role": "assistant",
"content": "This program prints FizzBuzz for the numbers from 1 to 100.\n```python\n# classic fizzbuzz from 1 to 100\nfor n in range(1, 101):\n if n % 15 == 0:\n print(\"FizzBuzz\")\n elif n % ... | glm-5.3-flash | qa-v1 | train | 164 | |
51b7a94a34ea7204 | en | code_python | write me a factorial but using a loop no recursion thx | It multiplies every number from 2 up to your number to get the factorial, all inside a for loop.
```python
# factorial using a loop
n = int(input("number: "))
result = 1
for i in range(2, n + 1):
result = result * i
print(n, "factorial is", result)
```
Run it with "python3 fact.py" and type a number. With 5 it pr... | [
{
"role": "user",
"content": "write me a factorial but using a loop no recursion thx"
},
{
"role": "assistant",
"content": "It multiplies every number from 2 up to your number to get the factorial, all inside a for loop.\n\n```python\n# factorial using a loop\nn = int(input(\"number: \"))\nresul... | hy4-preview | qa-v1 | train | 126 | |
796dcf0b92b82f0e | en | code_python | need a password strength checker in python, it should say weak ok or strong | This script rates a password as weak, OK or strong.
```python
# rates a password as weak, ok or strong
password = input("Password: ")
score = 0
if len(password) >= 8:
score += 1
if any(c.isdigit() for c in password):
score += 1
if any(c.isupper() for c in password):
score += 1
if any(not c.isalnum() for c i... | [
{
"role": "user",
"content": "need a password strength checker in python, it should say weak ok or strong"
},
{
"role": "assistant",
"content": "This script rates a password as weak, OK or strong.\n```python\n# rates a password as weak, ok or strong\npassword = input(\"Password: \")\nscore = 0\n... | glm-5.3-flash | qa-v1 | train | 216 | |
f579183c02af7231 | en | code_python | python program that finds the greatest common divisor of two numbers pls | This program reads two numbers and prints their greatest common divisor.
```python
# greatest common divisor with the Euclidean algorithm
a = int(input("first number: "))
b = int(input("second number: "))
while b:
a, b = b, a % b
print("GCD:", a)
```
Save it as gcd.py and run it with "python3 gcd.py". Type 48 and 1... | [
{
"role": "user",
"content": "python program that finds the greatest common divisor of two numbers pls"
},
{
"role": "assistant",
"content": "This program reads two numbers and prints their greatest common divisor.\n```python\n# greatest common divisor with the Euclidean algorithm\na = int(input... | glm-5.3-flash | qa-v1 | train | 120 | |
b931d2eea8f424f1 | en | code_python | make me a simple to do list in python, it can just live in memory | This program keeps a to-do list in memory while it runs.
```python
# a tiny to-do list, it lives only while the program runs
todos = []
while True:
action = input("add, done, list or quit: ").strip().lower()
if action == "add":
todos.append(input("New task: "))
print("Task added.")
elif acti... | [
{
"role": "user",
"content": "make me a simple to do list in python, it can just live in memory"
},
{
"role": "assistant",
"content": "This program keeps a to-do list in memory while it runs.\n```python\n# a tiny to-do list, it lives only while the program runs\ntodos = []\nwhile True:\n acti... | glm-5.3-flash | qa-v1 | train | 265 | |
a2b402f3863aaaa8 | en | code_python | write a python program that finds the largest number in a list without using max() | This program reads numbers from the user and finds the largest one with a loop instead of max().
```python
numbers = input("Numbers: ").split()
largest = int(numbers[0]) # start with the first one
for n in numbers[1:]:
if int(n) > largest:
largest = int(n)
print("Largest:", largest)
```
Run it with "p... | [
{
"role": "user",
"content": "write a python program that finds the largest number in a list without using max()"
},
{
"role": "assistant",
"content": "This program reads numbers from the user and finds the largest one with a loop instead of max().\n```python\nnumbers = input(\"Numbers: \").spli... | glm-5.3-flash | qa-v1 | train | 146 | |
87c790bbbb3b6ef1 | en | code_python | python fibonacci sequence like 10 numbers | This prints the first 10 numbers of the Fibonacci sequence.
```python
a, b = 0, 1
for _ in range(10):
print(a)
a, b = b, a + b
```
Save it as fib.py and run "python3 fib.py". It prints 0, 1, 1, 2, 3, 5, 8, 13, 21 and 34, one per line. | [
{
"role": "user",
"content": "python fibonacci sequence like 10 numbers"
},
{
"role": "assistant",
"content": "This prints the first 10 numbers of the Fibonacci sequence.\n\n```python\na, b = 0, 1\nfor _ in range(10):\n print(a)\n a, b = b, a + b\n```\n\nSave it as fib.py and run \"python3... | hy4-preview | qa-v1 | train | 117 | |
e1def07b1b6c22ff | en | code_python | write a python program that prints the squares of 1 to 10, use a list comprehension pls | This prints the squares of the numbers from 1 to 10 using a list comprehension.
```python
# squares of 1 to 10 with a list comprehension
squares = [n * n for n in range(1, 11)]
print(squares)
```
Save it as squares.py and run it with "python3 squares.py". It prints [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]. | [
{
"role": "user",
"content": "write a python program that prints the squares of 1 to 10, use a list comprehension pls"
},
{
"role": "assistant",
"content": "This prints the squares of the numbers from 1 to 10 using a list comprehension.\n```python\n# squares of 1 to 10 with a list comprehension\... | glm-5.3-flash | qa-v1 | train | 142 | |
1c0ba951c61e301a | en | code_python | how do i check if two words are anagrams in python | This script reads two words and prints whether they are anagrams.
```python
# anagrams use the same letters, just in a different order
word1 = input("First word: ")
word2 = input("Second word: ")
if sorted(word1.lower()) == sorted(word2.lower()):
print("Yes, they are anagrams!")
else:
print("No, they are not a... | [
{
"role": "user",
"content": "how do i check if two words are anagrams in python"
},
{
"role": "assistant",
"content": "This script reads two words and prints whether they are anagrams.\n```python\n# anagrams use the same letters, just in a different order\nword1 = input(\"First word: \")\nword2... | glm-5.3-flash | qa-v1 | train | 166 | |
1d6c248e2f2ccc8e | en | code_python | need a phone book program using a dictionary in python | This program stores three contacts in a dictionary and looks up the name you type.
```python
phone_book = {"Alice": "555-0101", "Ben": "555-0102", "Clara": "555-0103"}
name = input("Who are you looking for? ")
print(phone_book.get(name, "Not in the book."))
```
Run it with "python3 phonebook.py" and type Ben. It prints... | [
{
"role": "user",
"content": "need a phone book program using a dictionary in python"
},
{
"role": "assistant",
"content": "This program stores three contacts in a dictionary and looks up the name you type.\n```python\nphone_book = {\"Alice\": \"555-0101\", \"Ben\": \"555-0102\", \"Clara\": \"55... | glm-5.3-flash | qa-v1 | train | 151 | |
c1cdc31e9181d7c1 | en | code_python | make me a simple calculator python, reads 2 numbers and an operator | This program reads two numbers and an operator (+, -, * or /) and prints the result.
```python
# simple calculator: two numbers and an operator
a = float(input("First number: "))
op = input("Operator (+ - * /): ")
b = float(input("Second number: "))
if op == "+":
print(a + b)
elif op == "-":
print(a - b)
elif... | [
{
"role": "user",
"content": "make me a simple calculator python, reads 2 numbers and an operator"
},
{
"role": "assistant",
"content": "This program reads two numbers and an operator (+, -, * or /) and prints the result.\n\n```python\n# simple calculator: two numbers and an operator\na = float(... | hy4-preview | qa-v1 | train | 211 | |
7c87468239802114 | en | code_python | code for sum and average of a list of numbers python | This program adds up a list of numbers and works out their average.
```python
numbers = [4, 8, 15, 16, 23, 42]
total = sum(numbers)
average = total / len(numbers)
print("Sum:", total)
print("Average:", round(average, 2))
```
Save it as average.py, run it with python3 average.py and change the numbers list to use your... | [
{
"role": "user",
"content": "code for sum and average of a list of numbers python"
},
{
"role": "assistant",
"content": "This program adds up a list of numbers and works out their average.\n\n```python\nnumbers = [4, 8, 15, 16, 23, 42]\ntotal = sum(numbers)\naverage = total / len(numbers)\nprin... | hy4-preview | qa-v1 | train | 141 | |
6ea47f22540c6c75 | en | code_python | hey make me a multiplication table program in python | The program asks for a number and prints its times table from 1 to 10.
```python
# print the times table for a number, 1 to 10
n = int(input("Number: "))
for i in range(1, 11):
print(f"{n} x {i} = {n * i}")
```
Run it with "python3 times.py". With 7 it prints 7 x 1 = 7 through 7 x 10 = 70, one row per line. | [
{
"role": "user",
"content": "hey make me a multiplication table program in python"
},
{
"role": "assistant",
"content": "The program asks for a number and prints its times table from 1 to 10.\n```python\n# print the times table for a number, 1 to 10\nn = int(input(\"Number: \"))\nfor i in range... | glm-5.3-flash | qa-v1 | train | 132 | |
28d626950a1a22e3 | en | code_python | make me a simple todo list in python, just in memory no files | This program keeps a small to-do list in memory and lets you add, show and finish tasks.
```python
# simple to-do list in memory
tasks = []
while True:
cmd = input("add/show/done/quit: ").strip().lower()
if cmd == "add":
tasks.append(input("task: "))
elif cmd == "show":
for i, task in enumer... | [
{
"role": "user",
"content": "make me a simple todo list in python, just in memory no files"
},
{
"role": "assistant",
"content": "This program keeps a small to-do list in memory and lets you add, show and finish tasks.\n```python\n# simple to-do list in memory\ntasks = []\nwhile True:\n cmd ... | glm-5.3-flash | qa-v1 | train | 232 | |
c2139f83887ce1e4 | en | code_python | write a factorial function in python, with recursion pls | This program computes the factorial of a number with a recursive function.
```python
# factorial of a number using recursion
def factorial(n):
if n <= 1:
return 1
return n * factorial(n - 1)
print(factorial(5))
```
Save it as factorial.py and run it with "python3 factorial.py". It prints 120, which is ... | [
{
"role": "user",
"content": "write a factorial function in python, with recursion pls"
},
{
"role": "assistant",
"content": "This program computes the factorial of a number with a recursive function.\n```python\n# factorial of a number using recursion\ndef factorial(n):\n if n <= 1:\n ... | glm-5.3-flash | qa-v1 | train | 118 | |
0c0ac7d965f4da0e | en | code_python | whats the python way to find the longest word in a sentence | This program finds the longest word in a sentence you type.
```python
# find the longest word in a sentence
sentence = input()
words = sentence.split()
longest = max(words, key=len)
print("longest word:", longest)
```
Run it with "python3 longest.py" and type a sentence like "The quick brown fox jumps". It prints "long... | [
{
"role": "user",
"content": "whats the python way to find the longest word in a sentence"
},
{
"role": "assistant",
"content": "This program finds the longest word in a sentence you type.\n```python\n# find the longest word in a sentence\nsentence = input()\nwords = sentence.split()\nlongest = ... | glm-5.3-flash | qa-v1 | train | 116 | |
cf40c144e61568ec | en | code_python | pls code a program that prints a triangle of stars | This program prints a right triangle of stars with as many rows as you ask.
```python
n = int(input("How many rows? "))
for i in range(1, n + 1):
print("*" * i)
```
Run it with "python3 triangle.py" and type 5. It prints one star, then two, up to five stars on the last line. | [
{
"role": "user",
"content": "pls code a program that prints a triangle of stars"
},
{
"role": "assistant",
"content": "This program prints a right triangle of stars with as many rows as you ask.\n```python\nn = int(input(\"How many rows? \"))\nfor i in range(1, n + 1):\n print(\"*\" * i)\n``... | glm-5.3-flash | qa-v1 | train | 98 | |
e3a38909db036320 | en | code_python | make me a python script that prints the fibonacci sequence | This program prints the first 15 Fibonacci numbers.
```python
# print the first 15 fibonacci numbers
a, b = 0, 1
for _ in range(15):
print(a)
a, b = b, a + b
```
Save it as fib.py and run it with "python3 fib.py". It prints 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233 and 377, one per line. | [
{
"role": "user",
"content": "make me a python script that prints the fibonacci sequence"
},
{
"role": "assistant",
"content": "This program prints the first 15 Fibonacci numbers.\n```python\n# print the first 15 fibonacci numbers\na, b = 0, 1\nfor _ in range(15):\n print(a)\n a, b = b, a ... | glm-5.3-flash | qa-v1 | train | 152 | |
c3d7423ede2f0877 | en | code_python | hey, need a countdown from 5 to 1 in python | This program counts down from 5 to 1 and then prints Go.
```python
# countdown from 5 to 1
for i in range(5, 0, -1):
print(i)
print("Go")
```
Save it as countdown.py and run it with "python3 countdown.py". It prints 5, 4, 3, 2, 1 and Go, each on its own line. | [
{
"role": "user",
"content": "hey, need a countdown from 5 to 1 in python"
},
{
"role": "assistant",
"content": "This program counts down from 5 to 1 and then prints Go.\n```python\n# countdown from 5 to 1\nfor i in range(5, 0, -1):\n print(i)\nprint(\"Go\")\n```\nSave it as countdown.py and ... | glm-5.3-flash | qa-v1 | train | 110 | |
10cb26f4d8ecdbef | en | code_python | pyhton reverse a string pls | This program reads a line and prints it reversed.
```python
text = input()
print(text[::-1])
```
Run it with Python 3, type a word, and it prints the reversed word. | [
{
"role": "user",
"content": "pyhton reverse a string pls"
},
{
"role": "assistant",
"content": "This program reads a line and prints it reversed.\n```python\ntext = input()\nprint(text[::-1])\n```\nRun it with Python 3, type a word, and it prints the reversed word."
}
] | beam-free | qa-v1 | train | 52 | |
fba8f84678a87397 | en | code_python | hey can u convert celsius to fahrenheit in python pls | This program asks for a temperature in Celsius and prints it in Fahrenheit.
```python
c = float(input("Celsius: "))
f = c * 9 / 5 + 32
print(c, "C is", round(f, 1), "F")
```
Save it as celsius.py and run it with python3 celsius.py. Typing 20 prints: 20.0 C is 68.0 F. | [
{
"role": "user",
"content": "hey can u convert celsius to fahrenheit in python pls"
},
{
"role": "assistant",
"content": "This program asks for a temperature in Celsius and prints it in Fahrenheit.\n\n```python\nc = float(input(\"Celsius: \"))\nf = c * 9 / 5 + 32\nprint(c, \"C is\", round(f, 1)... | hy4-preview | qa-v1 | train | 115 | |
4602a5b56ea5888d | en | code_python | write a number guessing game python that reads guesses with input() | This picks a random number from 1 to 10 and tells you after each guess whether you were too low or too high.
```python
# number guessing game
import random
secret = random.randint(1, 10)
while True:
guess = int(input("guess 1-10: "))
if guess == secret:
print("you got it, it was", secret)
brea... | [
{
"role": "user",
"content": "write a number guessing game python that reads guesses with input()"
},
{
"role": "assistant",
"content": "This picks a random number from 1 to 10 and tells you after each guess whether you were too low or too high.\n```python\n# number guessing game\nimport random\... | hy4-preview | qa-v1 | train | 165 | |
c1b5b38b207b354a | en | code_python | make a multiplication table for 7 in python | This program prints the whole multiplication table of 7.
```python
n = 7
# print 7 times 1 up to 7 times 10
for i in range(1, 11):
print(n, "x", i, "=", n * i)
```
Save it as table.py and run it with python3 table.py. It prints 7 x 1 = 7 down to 7 x 10 = 70, one line each. | [
{
"role": "user",
"content": "make a multiplication table for 7 in python"
},
{
"role": "assistant",
"content": "This program prints the whole multiplication table of 7.\n```python\nn = 7\n\n# print 7 times 1 up to 7 times 10\nfor i in range(1, 11):\n print(n, \"x\", i, \"=\", n * i)\n```\nSa... | glm-5.3-flash | qa-v1 | train | 119 | |
2683f974ba328bb1 | en | code_python | write me fizzbuzz 1 to 100 in python | This one prints FizzBuzz from 1 to 100.
```python
for n in range(1, 101):
if n % 15 == 0:
print("FizzBuzz")
elif n % 3 == 0:
print("Fizz")
elif n % 5 == 0:
print("Buzz")
else:
print(n)
```
Save it as fizzbuzz.py and run it with python3 fizzbuzz.py. Multiples of 3 print Fi... | [
{
"role": "user",
"content": "write me fizzbuzz 1 to 100 in python"
},
{
"role": "assistant",
"content": "This one prints FizzBuzz from 1 to 100.\n```python\nfor n in range(1, 101):\n if n % 15 == 0:\n print(\"FizzBuzz\")\n elif n % 3 == 0:\n print(\"Fizz\")\n elif n % 5 =... | hy4-preview | qa-v1 | train | 166 | |
fe6b53a76eba01d0 | en | code_python | python script to capitalize every word in a sentence pls | This reads a sentence and capitalizes the first letter of every word.
```python
sentence = input("Type a sentence: ")
print(sentence.title())
```
Run it, type a sentence like "hello there, my name is bob", and it prints "Hello There, My Name Is Bob". No imports are needed, because title() does all the work. | [
{
"role": "user",
"content": "python script to capitalize every word in a sentence pls"
},
{
"role": "assistant",
"content": "This reads a sentence and capitalizes the first letter of every word.\n```python\nsentence = input(\"Type a sentence: \")\nprint(sentence.title())\n```\nRun it, type a se... | hy4-preview | qa-v1 | train | 90 | |
622d59ce689a4cbd | en | code_python | i need a password strength checker, python 3 | This gives a password a strength label from "very weak" to "very strong".
```python
password = input("Password: ")
score = 0
if len(password) >= 8:
score += 1
if any(c.isdigit() for c in password):
score += 1
if any(c.isupper() for c in password) and any(c.islower() for c in password):
score += 1
if any(no... | [
{
"role": "user",
"content": "i need a password strength checker, python 3"
},
{
"role": "assistant",
"content": "This gives a password a strength label from \"very weak\" to \"very strong\".\n\n```python\npassword = input(\"Password: \")\nscore = 0\nif len(password) >= 8:\n score += 1\nif an... | hy4-preview | qa-v1 | train | 234 | |
f47eaa46dc8b0def | en | code_python | could you do a gcd program in python, the euclid way | It finds the greatest common divisor of two numbers with the Euclidean algorithm.
```python
# greatest common divisor with the Euclidean algorithm
a = int(input("First number: "))
b = int(input("Second number: "))
while b != 0:
a, b = b, a % b
print("GCD:", a)
```
Save it as gcd.py and run it with "python3 gcd.py... | [
{
"role": "user",
"content": "could you do a gcd program in python, the euclid way"
},
{
"role": "assistant",
"content": "It finds the greatest common divisor of two numbers with the Euclidean algorithm.\n\n```python\n# greatest common divisor with the Euclidean algorithm\na = int(input(\"First ... | glm-5.3-flash | qa-v1 | train | 134 | |
eb57d58d76ee6137 | en | code_python | how do you swap two variables in python | This swaps the values of two variables in one line, with no temporary variable needed.
```python
a = 5
b = 9
print("Before:", a, b)
a, b = b, a # Python swaps them in one step
print("After:", a, b)
```
Save it as swap.py and run it with "python3 swap.py". It prints "Before: 5 9" and "After: 9 5". | [
{
"role": "user",
"content": "how do you swap two variables in python"
},
{
"role": "assistant",
"content": "This swaps the values of two variables in one line, with no temporary variable needed.\n```python\na = 5\nb = 9\n\nprint(\"Before:\", a, b)\na, b = b, a # Python swaps them in on... | hy4-preview | qa-v1 | train | 116 | |
c858d99018bae20d | en | code_word | 12 sweets are shared equally among 2 children. How many does each child get? | 12 ÷ 2 = 6.
The answer is 6. | [
{
"role": "user",
"content": "12 sweets are shared equally among 2 children. How many does each child get?"
},
{
"role": "assistant",
"content": "12 ÷ 2 = 6.\nThe answer is 6."
}
] | code | qa-v1 | train | 35 | |
d61cdf74c5b3d27a | en | code_word | Tom reads 33 pages a day. How many pages will Tom read in 11 days? | 33 × 11 = 363.
The answer is 363. | [
{
"role": "user",
"content": "Tom reads 33 pages a day. How many pages will Tom read in 11 days?"
},
{
"role": "assistant",
"content": "33 × 11 = 363.\nThe answer is 363."
}
] | code | qa-v1 | train | 43 | |
68c21b8c01b55d9e | en | code_word | Oliver saves $15 every week. How many weeks does it take to save $90? | 90 ÷ 15 = 6.
The answer is 6 weeks. | [
{
"role": "user",
"content": "Oliver saves $15 every week. How many weeks does it take to save $90?"
},
{
"role": "assistant",
"content": "90 ÷ 15 = 6.\nThe answer is 6 weeks."
}
] | code | qa-v1 | train | 42 | |
769b59009d0fa790 | en | code_word | 30 sweets are shared equally among 6 children. How many does each child get? | 30 ÷ 6 = 5.
The answer is 5. | [
{
"role": "user",
"content": "30 sweets are shared equally among 6 children. How many does each child get?"
},
{
"role": "assistant",
"content": "30 ÷ 6 = 5.\nThe answer is 5."
}
] | code | qa-v1 | train | 35 | |
4008dc29556518ac | en | code_word | A rectangle is 18 cm long and 15 cm wide. What is its area? | Area = length × width = 18 × 15 = 270 cm².
The answer is 270 cm². | [
{
"role": "user",
"content": "A rectangle is 18 cm long and 15 cm wide. What is its area?"
},
{
"role": "assistant",
"content": "Area = length × width = 18 × 15 = 270 cm².\nThe answer is 270 cm²."
}
] | code | qa-v1 | train | 56 | |
296ae33f2be39ede | en | code_word | Grace has 9 packs with 12 pencils in each. Grace gives away 1. How many pencils are left? | 9 × 12 = 108 pencils, then 108 - 1 = 107.
The answer is 107. | [
{
"role": "user",
"content": "Grace has 9 packs with 12 pencils in each. Grace gives away 1. How many pencils are left?"
},
{
"role": "assistant",
"content": "9 × 12 = 108 pencils, then 108 - 1 = 107.\nThe answer is 107."
}
] | code | qa-v1 | train | 64 | |
e97cd4116c8949ec | en | code_word | Ben has 7 packs with 6 pencils in each. Ben gives away 11. How many pencils are left? | 7 × 6 = 42 pencils, then 42 - 11 = 31.
The answer is 31. | [
{
"role": "user",
"content": "Ben has 7 packs with 6 pencils in each. Ben gives away 11. How many pencils are left?"
},
{
"role": "assistant",
"content": "7 × 6 = 42 pencils, then 42 - 11 = 31.\nThe answer is 31."
}
] | code | qa-v1 | train | 59 | |
25af634d9b0eaca8 | en | code_word | Sam reads 30 pages a day. How many pages will Sam read in 5 days? | 30 × 5 = 150.
The answer is 150. | [
{
"role": "user",
"content": "Sam reads 30 pages a day. How many pages will Sam read in 5 days?"
},
{
"role": "assistant",
"content": "30 × 5 = 150.\nThe answer is 150."
}
] | code | qa-v1 | train | 41 | |
0457100baf907e0f | en | code_word | A car drives at 100 km/h for 4 hours. How far does it go? | Distance = speed × time = 100 × 4 = 400 km.
The answer is 400 km. | [
{
"role": "user",
"content": "A car drives at 100 km/h for 4 hours. How far does it go?"
},
{
"role": "assistant",
"content": "Distance = speed × time = 100 × 4 = 400 km.\nThe answer is 400 km."
}
] | code | qa-v1 | train | 55 | |
87b2a1cae4c24afc | en | code_word | 18 sweets are shared equally among 2 children. How many does each child get? | 18 ÷ 2 = 9.
The answer is 9. | [
{
"role": "user",
"content": "18 sweets are shared equally among 2 children. How many does each child get?"
},
{
"role": "assistant",
"content": "18 ÷ 2 = 9.\nThe answer is 9."
}
] | code | qa-v1 | train | 35 | |
c14bcb9e1f3e2394 | en | code_word | A rectangle is 19 cm long and 5 cm wide. What is its perimeter? | Perimeter = 2 × (length + width) = 2 × (19 + 5) = 2 × 24 = 48 cm.
The answer is 48 cm. | [
{
"role": "user",
"content": "A rectangle is 19 cm long and 5 cm wide. What is its perimeter?"
},
{
"role": "assistant",
"content": "Perimeter = 2 × (length + width) = 2 × (19 + 5) = 2 × 24 = 48 cm.\nThe answer is 48 cm."
}
] | code | qa-v1 | train | 72 | |
a47beb9900b8c0ba | en | code_word | Lucy has 8 boxes with 8 apples in each. Lucy gives away 41. How many apples are left? | 8 × 8 = 64 apples, then 64 - 41 = 23.
The answer is 23. | [
{
"role": "user",
"content": "Lucy has 8 boxes with 8 apples in each. Lucy gives away 41. How many apples are left?"
},
{
"role": "assistant",
"content": "8 × 8 = 64 apples, then 64 - 41 = 23.\nThe answer is 23."
}
] | code | qa-v1 | train | 61 | |
234de6e7273dc7a6 | en | code_word | Anna saves $10 every week. How many weeks does it take to save $110? | 110 ÷ 10 = 11.
The answer is 11 weeks. | [
{
"role": "user",
"content": "Anna saves $10 every week. How many weeks does it take to save $110?"
},
{
"role": "assistant",
"content": "110 ÷ 10 = 11.\nThe answer is 11 weeks."
}
] | code | qa-v1 | train | 46 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.