Dataset Viewer
Auto-converted to Parquet Duplicate
messages
listlengths
2
2
[ { "content": "```python\nimport time\nprint(time.ctime())\n```", "role": "user" }, { "content": "This code prints the current date and time.", "role": "assistant" } ]
[ { "content": "```python\ndef transform_strings(words):\n results = []\n for w in words:\n lower_w = w.lower()\n upper_w = w.upper()\n title_w = w.title()\n cap_w = w.capitalize()\n results.append((lower_w, upper_w, title_w, cap_w))\n for item in results:\n print(item)\n return results\n\ntransform_strings([\"hELLo\", \"wORLD\", \"pYtHoN\"])\n```", "role": "user" }, { "content": "This code changes words into lowercase, uppercase, title case, and capitalized forms.", "role": "assistant" } ]
[ { "content": "```python\ndef countdown(n):\n while n > 0:\n print(n)\n n -= 1\n print(\"Done!\")\n\ncountdown(5)\n```", "role": "user" }, { "content": "This code counts down from a number until it reaches zero.", "role": "assistant" } ]
[ { "content": "```python\nimport sys\n\ndef show_sys_info():\n print(\"Python version:\")\n print(sys.version)\n print(\"\\nCommand-line arguments:\")\n for arg in sys.argv:\n print(arg)\n print(\"\\nModule search paths:\")\n for p in sys.path:\n print(p)\n print(\"\\nPlatform:\")\n print(sys.platform)\n\nshow_sys_info()\n```", "role": "user" }, { "content": "This code shows information about Python's version, arguments, search paths, and platform.", "role": "assistant" } ]
[ { "content": "```python\nimport time\nprint(time.time())\n```", "role": "user" }, { "content": "This code prints the current time in seconds.", "role": "assistant" } ]
[ { "content": "```python\ncount = 0\nwhile count < 5:\n print(count)\n count += 1\n```", "role": "user" }, { "content": "This code repeats a loop until count reaches 5.", "role": "assistant" } ]
[ { "content": "```python\ndef combine_strings_and_list(words, ending):\n result = \"\"\n for w in words:\n result += w + ending\n return result\n\nitems = [\"sun\", \"rain\", \"wind\"]\nfinal = combine_strings_and_list(items, \"shine\")\nprint(final)\n```", "role": "user" }, { "content": "This code makes a function that joins each word in a list with extra text and prints the combined result.", "role": "assistant" } ]
[ { "content": "```python\ninfo = {\"name\": \"Ana\", \"age\": 12}\nvalue = info.get(\"age\")\nmessage = \"{0} is {1} years old\".format(info.get(\"name\"), value)\nprint(message)\n```", "role": "user" }, { "content": "This code gets values from a dictionary safely and uses them to create a sentence.", "role": "assistant" } ]
[ { "content": "```python\nraise ValueError(\"Something went wrong!\")\n```", "role": "user" }, { "content": "This code forces an error to stop the program when something is wrong.", "role": "assistant" } ]
[ { "content": "```python\nnum = int(\"42\")\n```", "role": "user" }, { "content": "This code turns a string into an integer.", "role": "assistant" } ]
[ { "content": "```python\n# Working with tuples in a function\n\ndef analyze_scores(scores):\n highest = max(scores)\n lowest = min(scores)\n total = sum(scores)\n count = len(scores)\n average = total / count\n return (highest, lowest, total, count, average)\n\nstudent_scores = (85, 92, 78, 90, 88)\nresults = analyze_scores(student_scores)\nprint(results)\n```", "role": "user" }, { "content": "This code uses a tuple of numbers and returns helpful facts about it, like the highest score and average.", "role": "assistant" } ]
[ { "content": "```python\nclass Test:\n def __secret(self):\n return \"hidden\"\n```", "role": "user" }, { "content": "This code shows a private method that starts with double underscores to hide it inside the class.", "role": "assistant" } ]
[ { "content": "```python\nimport sys\n\ndef print_sys_info():\n print(sys.version)\n print(sys.platform)\n print(sys.executable)\n print(len(sys.argv))\n\nprint_sys_info()\n```", "role": "user" }, { "content": "This code shows information about Python using the sys module.", "role": "assistant" } ]
[ { "content": "```python\nname = input(\"Name: \")\nprint(name)\n```", "role": "user" }, { "content": "This code asks the user to type something and then prints it.", "role": "assistant" } ]
[ { "content": "```python\nis_sunny = True\nprint(is_sunny)\n```", "role": "user" }, { "content": "This code uses a boolean value and prints it.", "role": "assistant" } ]
[ { "content": "```python\nclass Animal:\n def __init__(self, name):\n self.name = name\n def speak(self):\n return self.name + \" makes a sound\"\ndog = Animal(\"Dog\")\nprint(dog.speak())\n```", "role": "user" }, { "content": "This code makes a simple class that stores a name and prints a message.", "role": "assistant" } ]
[ { "content": "```python\nclass Book:\n def __init__(self, title):\n self.title = title\nmy_book = Book(\"Math Guide\")\nprint(my_book.title)\n```", "role": "user" }, { "content": "This code creates a class for books and prints the book’s title.", "role": "assistant" } ]
[ { "content": "```python\ndef process_tuples(data):\n results = []\n for item in data:\n a, b = item\n total = a + b\n results.append((a, b, total))\n for r in results:\n print(r)\nsample = [(1, 2), (3, 4), (5, 6)]\nprocess_tuples(sample)\n```", "role": "user" }, { "content": "This code adds numbers inside tuples and prints the results.", "role": "assistant" } ]
[ { "content": "```python\nnums = [1, 2, 3, 4]\ndoubled = list(map(lambda x: x * 2, nums))\nprint(doubled)\n```", "role": "user" }, { "content": "This code uses a lambda to double each number in a list.", "role": "assistant" } ]
[ { "content": "```python\ndef add_numbers(a, b):\n if not isinstance(a, int) or not isinstance(b, int):\n raise TypeError(\"Both must be integers\")\n if a < 0 or b < 0:\n raise ValueError(\"Numbers must be positive\")\n return a + b\nprint(add_numbers(3, 4))\n```", "role": "user" }, { "content": "This code checks for bad inputs and raises errors if something is wrong.", "role": "assistant" } ]
[ { "content": "```python\nraise ValueError(\"Something went wrong!\")\n```", "role": "user" }, { "content": "This code purposely creates an error to stop the program when something is wrong.", "role": "assistant" } ]
[ { "content": "```python\nresult = 7 >= 3\n```", "role": "user" }, { "content": "This code compares two numbers and checks if one is greater than or equal to the other.", "role": "assistant" } ]
[ { "content": "```python\ndef count_items(lst):\n total = len(lst)\n print(\"Total items:\", total)\n for i in range(total):\n print(\"Index\", i, \"has\", lst[i])\n if total == 0:\n print(\"List is empty\")\n else:\n print(\"First item:\", lst[0])\n print(\"Last item:\", lst[-1])\n return total\n```", "role": "user" }, { "content": "This function uses len() to count items in a list and show information about them.", "role": "assistant" } ]
[ { "content": "```python\ndef double_values(nums):\n return list(map(lambda x: x * 2, nums))\n```", "role": "user" }, { "content": "This function uses map to double each number in a list.", "role": "assistant" } ]
[ { "content": "```python\nvalue = {\"x\": 10}.get(\"x\")\n```", "role": "user" }, { "content": "This code uses get to safely read a value from a dictionary.", "role": "assistant" } ]
[ { "content": "```python\nwith open(\"example.txt\", \"w\") as f:\n f.write(\"Hello!\\n\")\n f.write(\"This file was opened with 'with'.\\n\")\n\ndef read_file():\n with open(\"example.txt\", \"r\") as f:\n data = f.read()\n return data\n```", "role": "user" }, { "content": "This code uses the with keyword to safely open and close a file. It writes text to the file, then reads it back using a function.", "role": "assistant" } ]
[ { "content": "```python\nname = \"Hello, \" + \"world!\"\njoined = [1,2] + [3,4]\n```", "role": "user" }, { "content": "This code shows how to join strings and lists using the + symbol.", "role": "assistant" } ]
[ { "content": "```python\nx = 0\nwhile x < 3:\n x += 1\n```", "role": "user" }, { "content": "This code uses a while loop to grow the number x until it reaches 3.", "role": "assistant" } ]
[ { "content": "```python\nfrom math import sqrt as square_root\n\ndef analyze_numbers(nums):\n results = []\n for n in nums:\n if n >= 0:\n r = square_root(n)\n results.append((n, r))\n else:\n results.append((n, None))\n return results\n\ndata = [4, 9, 16, -1]\noutcome = analyze_numbers(data)\n```", "role": "user" }, { "content": "This code uses from to import a function and as to rename it. The function checks numbers and finds their square roots if they are positive.", "role": "assistant" } ]
[ { "content": "```python\ninfo = {\"name\": \"Sam\", \"age\": 12}\nvalue = info.get(\"grade\", \"No grade found\")\nmessage = \"Student: {}\".format(info.get(\"name\"))\n```", "role": "user" }, { "content": "This code uses a dictionary’s get method to safely access values, and uses format to place text inside a string.", "role": "assistant" } ]
[ { "content": "```python\nmy_list = [1, 2]; my_list.append(3); my_list.remove(1)\n```", "role": "user" }, { "content": "This code adds a number to a list and then removes a number from it.", "role": "assistant" } ]
[ { "content": "```python\nimport time; current = time.time()\n```", "role": "user" }, { "content": "This code shows the current time in seconds since the computer time count began.", "role": "assistant" } ]
[ { "content": "```python\nlst=[3,1,2]; lst.copy(); lst.count(1); lst.extend([4]); lst.reverse(); lst.sort()\n```", "role": "user" }, { "content": "This code shows different ways to copy, count, add to, reverse, and sort a list.", "role": "assistant" } ]
[ { "content": "```python\ndef edit_list(items):\n items.append(\"new\")\n items.append(\"item\")\n if \"remove\" in items:\n items.remove(\"remove\")\n if \"old\" in items:\n items.remove(\"old\")\n return items\n```", "role": "user" }, { "content": "This function adds items to a list and removes certain ones if they are there.", "role": "assistant" } ]
[ { "content": "```python\ndef safe_divide(a, b):\n if not isinstance(a, (int,float)) or not isinstance(b, (int,float)):\n raise TypeError(\"Both values must be numbers\")\n if b == 0:\n raise ZeroDivisionError(\"Cannot divide by zero\")\n result = a / b\n return result\n\n# Example\n# safe_divide(10, 0)\n```", "role": "user" }, { "content": "This function checks for mistakes before dividing and raises errors when something is wrong.", "role": "assistant" } ]
[ { "content": "```python\nnums = [10, 20, 30]\nnums.insert(1, 15); x = nums.index(30); nums.pop(0)\n```", "role": "user" }, { "content": "This code adds a number into a list, finds where a number is located, and removes the first item.", "role": "assistant" } ]
[ { "content": "```python\nclass Dog: pass\nd = Dog()\n```", "role": "user" }, { "content": "This code makes a simple class and creates an object from it.", "role": "assistant" } ]
[ { "content": "```python\nclass Book:\n def __init__(self, title, author):\n self.title = title\n self.author = author\n def __str__(self):\n return self.title + \" by \" + self.author\nb = Book(\"Wonder\", \"R.J. Palacio\")\nprint(b)\n```", "role": "user" }, { "content": "This code sets up a class with built‑in methods so it can store information and print it nicely.", "role": "assistant" } ]
[ { "content": "```python\ntext = \"Hello World\"\nfor c in text:\n print(c.lower())\n```", "role": "user" }, { "content": "This code goes through each letter in a string and prints it in lowercase.", "role": "assistant" } ]
[ { "content": "```python\nx = 5 # this stores a number\nprint(x) # this prints it\n```", "role": "user" }, { "content": "This code shows how comments explain what each line does.", "role": "assistant" } ]
[ { "content": "```python\ndef multiply_list(nums): \\\n doubler = lambda x: x * 2 \\\n result = [] \\\n for n in nums: \\\n result.append(doubler(n)) \\\n return result \\\nprint(multiply_list([1, 2, 3])) \\\n```", "role": "user" }, { "content": "This code uses a lambda to double numbers in a list.", "role": "assistant" } ]
[ { "content": "```python\ndef safe_add(a, b): \\\n try: \\\n return a + b \\\n except TypeError: \\\n return \"TypeError happened\" \\\n except ValueError: \\\n return \"ValueError happened\" \\\nprint(safe_add(5, \"x\")) \\\n```", "role": "user" }, { "content": "This code shows how TypeError and ValueError are caught.", "role": "assistant" } ]
[ { "content": "```python\ndef get_numbers(): \\\n nums = [] \\\n print(\"Enter 3 numbers:\") \\\n for i in range(3): \\\n n = input(\"Number: \") \\\n nums.append(n) \\\n print(\"You typed:\") \\\n for x in nums: \\\n print(x) \\\n return nums \\\nget_numbers() \\\n```", "role": "user" }, { "content": "This code asks the user for numbers and prints them.", "role": "assistant" } ]
[ { "content": "```python\ndef divide(a, b): \\\n if b == 0: \\\n raise ValueError(\"Cannot divide by zero\") \\\n if not isinstance(a, (int, float)) or not isinstance(b, (int, float)): \\\n raise TypeError(\"Inputs must be numbers\") \\\n result = a / b \\\n print(\"Result is\", result) \\\n return result \\\n# divide(10, 0) \\\n```", "role": "user" }, { "content": "This code raises exceptions when the input is not allowed.", "role": "assistant" } ]
[ { "content": "```python\nx = 5 \\\nprint(\"Big\" if x > 3 else \"Small\") \\\n```", "role": "user" }, { "content": "This code prints one thing if a condition is true, another if false.", "role": "assistant" } ]
[ { "content": "```python\nx = 5\nif isinstance(x, int):\n print(\"x is an integer\")\nelse:\n print(\"x is not an integer\")\n```", "role": "user" }, { "content": "This code checks if x is an integer and prints a message based on the result.", "role": "assistant" } ]
[ { "content": "```python\ni = 0\nwhile i < 3:\n i += 1\n```", "role": "user" }, { "content": "This code repeats the loop while i is less than 3.", "role": "assistant" } ]
[ { "content": "```python\nx = 7\nif x < 5:\n print(\"small\")\nelif x < 10:\n print(\"medium\")\n```", "role": "user" }, { "content": "This code uses elif to check another condition when the first one is false.", "role": "assistant" } ]
[ { "content": "```python\ndef compare_numbers(a, b):\n if a != b:\n print(\"They are different\")\n if a > b:\n print(\"a is greater\")\n if a >= b:\n print(\"a is greater or equal\")\n if a < b:\n print(\"a is smaller\")\n if a <= b:\n print(\"a is smaller or equal\")\n\ncompare_numbers(3, 5)\n```", "role": "user" }, { "content": "This code compares two numbers using different comparison operators and prints the results.", "role": "assistant" } ]
[ { "content": "```python\ndef check_values(a, b):\n if a > 0 or b > 0:\n print(\"At least one is positive\")\n if not (a < 0):\n print(\"a is not negative\")\n if not (b < 0):\n print(\"b is not negative\")\n\ncheck_values(3, -2)\n```", "role": "user" }, { "content": "This code shows how or and not help check if values meet certain conditions.", "role": "assistant" } ]
[ { "content": "```python\nfrom typing import Tuple\n\ndef sum_tuple(nums: Tuple[int, int, int]) -> int:\n total = 0\n for n in nums:\n total += n\n return total\n\nprint(sum_tuple((1, 2, 3)))\n```", "role": "user" }, { "content": "This code makes a function that adds all numbers in a tuple and prints the total.", "role": "assistant" } ]
[ { "content": "```python\nname = \"Alex\"\\nprint(name)\n```", "role": "user" }, { "content": "This code stores a name and prints it to the screen.", "role": "assistant" } ]
[ { "content": "```python\nanimals = [\"cat\", \"dog\", \"bird\", \"fish\"]\\nanimals.remove(\"bird\")\\ndel animals[1]\n```", "role": "user" }, { "content": "This code removes items from a list using remove() and del.", "role": "assistant" } ]
[ { "content": "```python\nclass Book:\\n def __init__(self, title):\\n self.title = title\\n def __str__(self):\\n return f\"Book: {self.title}\"\\nprint(Book(\"Magic\"))\n```", "role": "user" }, { "content": "This code creates a class with __init__ to set a title and __str__ to show the book as text.", "role": "assistant" } ]
[ { "content": "```python\nnums = [4, 2, 7, 2]\\nnums_copy = nums.copy()\\ncount_twos = nums.count(2)\\nnums.extend([9, 1])\\nnums.reverse()\\nnums.sort()\\nnums.clear()\n```", "role": "user" }, { "content": "This code shows several list methods that copy, count, add, reverse, sort, and clear items.", "role": "assistant" } ]
[ { "content": "```python\nname = input(\"Enter your name: \")\nage = input(\"Enter your age: \")\ncity = input(\"Enter your city: \")\ndef greet_user(n, a, c):\n print(\"Hello, \" + n + \"!\")\n print(\"You are \" + a + \" years old.\")\n print(\"You live in \" + c + \".\")\n for i in range(3):\n print(\"Repeating your info:\")\n print(n + \", \" + a + \", from \" + c)\n print(\"Done!\")\ngreet_user(name, age, city)\n```", "role": "user" }, { "content": "This code asks you for your name, age, and city, then uses a function to print that information several times.", "role": "assistant" } ]
[ { "content": "```python\ntext = \"Hello World\"\nprint(text.lower())\nprint(text.upper())\nprint(\"Length:\", len(text))\n```", "role": "user" }, { "content": "This code works with a string by changing its case and showing how long the string is.", "role": "assistant" } ]
[ { "content": "```python\nstudent = {\"name\": \"Ava\", \"grade\": 92}\nprint(student.get(\"name\"))\ninfo = \"{0} scored {1}%\".format(student.get(\"name\"), student.get(\"grade\"))\nprint(info)\n```", "role": "user" }, { "content": "This code shows how to safely get values from a dictionary and use format to build a sentence.", "role": "assistant" } ]
[ { "content": "```python\ndef add_numbers():\n a = int(input(\"Enter a number: \"))\n b = int(input(\"Enter another number: \"))\n result = a + b\n print(\"The sum is\", result)\nadd_numbers()\n```", "role": "user" }, { "content": "This code asks you for two numbers, adds them together, and prints the answer.", "role": "assistant" } ]
[ { "content": "```python\nnums = [1, 2, 3, 4]\ndoubled = list(map(lambda x: x * 2, nums))\nprint(doubled)\n```", "role": "user" }, { "content": "This code uses map to double each number in a list.", "role": "assistant" } ]
[ { "content": "```python\ntry:\n x = int(\"hello\")\nexcept ValueError:\n print(\"ValueError happened\")\nexcept TypeError:\n print(\"TypeError happened\")\n```", "role": "user" }, { "content": "This code tries to turn text into a number, catches errors, and prints a message if something goes wrong.", "role": "assistant" } ]
[ { "content": "```python\na = 5\nb = \"hi\"\n```", "role": "user" }, { "content": "This code makes two variables: a number and a piece of text.", "role": "assistant" } ]
[ { "content": "```python\ncount = 0\nwhile count < 3:\n print(count)\n count += 1\n```", "role": "user" }, { "content": "This code repeats until the number reaches 3, printing the count each time.", "role": "assistant" } ]
[ { "content": "```python\nclass Animal:\n def __init__(self, name, sound):\n self.name = name\n self.sound = sound\n def speak(self):\n print(self.name + \" says \" + self.sound)\nclass Zoo:\n def __init__(self):\n self.animals = []\n def add_animal(self, animal):\n self.animals.append(animal)\n def show_all(self):\n for a in self.animals:\n a.speak()\nz = Zoo()\nz.add_animal(Animal(\"Dog\",\"Woof\"))\nz.add_animal(Animal(\"Cat\",\"Meow\"))\nz.show_all()\n```", "role": "user" }, { "content": "This code creates animals, puts them in a zoo, and makes them speak.", "role": "assistant" } ]
[ { "content": "```python\nraise ValueError(\"Bad input\")\nraise TypeError(\"Wrong type\")\n```", "role": "user" }, { "content": "This code forces two types of errors to happen on purpose.", "role": "assistant" } ]
[ { "content": "```python\nx = int(\"5\")\ny = int(3.7)\n```", "role": "user" }, { "content": "This code converts a string and a decimal number into whole numbers using int().", "role": "assistant" } ]
[ { "content": "```python\nfrom math import sqrt as square_root\nnum = 25\nresult = square_root(num)\nprint(result)\n```", "role": "user" }, { "content": "This code shows how from lets you import part of a module and how as lets you rename it to something shorter.", "role": "assistant" } ]
[ { "content": "```python\nnums = [10, 20, 30]\nnums.insert(1, 15); nums.pop(); i = nums.index(15)\n```", "role": "user" }, { "content": "This code adds a number, removes the last one, and finds where a number is in the list.", "role": "assistant" } ]
[ { "content": "```python\ndef find_word(word, sentence):\n for w in sentence.split():\n if word in w:\n return True\n return False\n\ntext = \"The lighthouse guides ships at night\"\nprint(find_word(\"light\", text))\nprint(find_word(\"moon\", text))\n```", "role": "user" }, { "content": "This code checks if a smaller word is found inside any word in a sentence using the in operator.", "role": "assistant" } ]
[ { "content": "```python\nx = 10 # this stores a number\ny = x * 2 # this doubles it\n```", "role": "user" }, { "content": "This code uses # to add comments that explain what each line does.", "role": "assistant" } ]
[ { "content": "```python\nclass Pet:\n def __init__(self, name):\n self.name = name\n def __str__(self):\n return \"Pet name: \" + self.name\npet = Pet(\"Buddy\")\nprint(pet)\n```", "role": "user" }, { "content": "This code creates a class with two built-in methods: __init__ sets up the object's data, and __str__ controls what prints when the object is shown.", "role": "assistant" } ]
[ { "content": "```python\ndef show_lines():\n text = \"Hello\\nWorld!\\nThis is a test.\"\n print(text)\n extra = \"Line 1\\nLine 2\\nLine 3\"\n print(extra)\nshow_lines()\n```", "role": "user" }, { "content": "This code uses the \\n character to create line breaks inside strings, so the printed text appears on multiple lines.", "role": "assistant" } ]
[ { "content": "```python\ndef check_values(a, b):\n if a > 5 or b > 5:\n print(\"At least one value is big\")\n if not (a < 3):\n print(\"a is not less than 3\")\n print(\"Done checking\")\ncheck_values(6, 2)\n```", "role": "user" }, { "content": "This code shows how or checks if one condition is true and how not flips a condition to its opposite.", "role": "assistant" } ]
[ { "content": "```python\ndef convert_to_float(x):\n y = float(x)\n print(\"Converted:\", y)\n doubled = y * 2\n print(\"Doubled:\", doubled)\nconvert_to_float(\"3.5\")\n```", "role": "user" }, { "content": "This code uses float() to change a string into a decimal number so it can be used in math.", "role": "assistant" } ]
[ { "content": "```python\nfrom math import sqrt as square_root\nnum = 16\nresult = square_root(num)\nprint(result)\n```", "role": "user" }, { "content": "This code uses from to import just one part of a module, and as to rename it for easier use.", "role": "assistant" } ]
[ { "content": "```python\ncounter = 0\nlimit = 5\ntotal = 0\nwhile counter < limit:\n total += counter\n counter += 1\n if counter == 3:\n total += 10\n if counter == 4:\n total -= 2\nprint('Final total:', total)\n```", "role": "user" }, { "content": "This code uses a while loop to add numbers and change the total until the counter reaches the limit.", "role": "assistant" } ]
[ { "content": "```python\ndef safe_add(a, b):\n try:\n return a + b\n except TypeError:\n return 'Type error!'\n except ValueError:\n return 'Value error!'\nprint(safe_add(3, 4))\nprint(safe_add(3, 'x'))\n```", "role": "user" }, { "content": "This code tries to add two things and shows a message if the types or values are wrong.", "role": "assistant" } ]
[ { "content": "```python\nx = 5\ny = x + 2\n```", "role": "user" }, { "content": "This code creates variables and stores numbers in them.", "role": "assistant" } ]
[ { "content": "```python\nresult = list(map(lambda n: n * 2, [1, 2, 3]))\n```", "role": "user" }, { "content": "This code uses map to double each number in a list.", "role": "assistant" } ]
[ { "content": "```python\ndef parse_int(text):\n try:\n num = int(text)\n return num\n except ValueError:\n return 'Not a number!'\n except TypeError:\n return 'Wrong type!'\nprint(parse_int('12'))\nprint(parse_int('hi'))\n```", "role": "user" }, { "content": "This code tries to turn text into a number and shows a message if something goes wrong.", "role": "assistant" } ]
[ { "content": "```python\nx = 10\ny = 5\nname = \"Alex\"\nresult = x + y\nmessage = f\"Hello, {name}!\"\nprint(result)\nprint(message)\n```", "role": "user" }, { "content": "This code makes a few variables, adds numbers together, and prints a message.", "role": "assistant" } ]
[ { "content": "```python\nnumbers = [1, 2, 3, 4, 5]\ndoubled = list(map(lambda n: n * 2, numbers))\nfiltered = list(filter(lambda n: n % 2 == 0, doubled))\nsquare = lambda x: x * x\nsquares = [square(n) for n in filtered]\ndef process(nums):\n add_one = lambda x: x + 1\n return [add_one(n) for n in nums]\nresult = process(squares)\nprint(result)\n```", "role": "user" }, { "content": "This code uses lambda functions to change numbers in different ways.", "role": "assistant" } ]
[ { "content": "```python\nimport random\nnum = random.randint(1, 10)\ncolors = [\"red\", \"blue\", \"green\"]\nchoice = random.choice(colors)\nprint(num)\nprint(choice)\n```", "role": "user" }, { "content": "This code picks a random number and a random color.", "role": "assistant" } ]
[ { "content": "```python\nprint(\"a\" in \"cat\")\nprint(3 in [1, 2, 3])\n```", "role": "user" }, { "content": "This code checks if something is inside a string or list.", "role": "assistant" } ]
[ { "content": "```python\nclass Robot:\n def __init__(self, name):\n self.name = name\n def greet(self):\n self.__secret()\n print(\"Hello, I am\", self.name)\n def __secret(self):\n print(\"This is a private robot message!\")\n\nr = Robot(\"Robo\")\nr.greet()\n# r.__secret() would cause an error\n```", "role": "user" }, { "content": "This code shows how double underscores make a method private inside a class.", "role": "assistant" } ]
[ { "content": "```python\n# Large function about float()\ndef clean_and_convert(numbers):\n cleaned = []\n for n in numbers:\n try:\n value = float(n)\n cleaned.append(value)\n except ValueError:\n cleaned.append(None)\n total = 0.0\n for x in cleaned:\n if x is not None:\n total += x\n return cleaned, total\n\nresult = clean_and_convert([\"3.14\", \"5\", \"abc\", \"2.6\"])\nprint(result)\n```", "role": "user" }, { "content": "This code turns strings into decimal numbers using float(), skips errors, and adds the valid numbers together.", "role": "assistant" } ]
[ { "content": "```python\n\"hello world\".find(\"world\")\n\"-\".join([\"a\", \"b\", \"c\"])\n```", "role": "user" }, { "content": "This code finds where a word appears in a string and joins letters with dashes.", "role": "assistant" } ]
[ { "content": "```python\nitems = [10, 20, 30, 40]\nposition = items.index(30)\nremoved = items.pop(1)\nitems.insert(1, 99)\nprint(items, position, removed)\n```", "role": "user" }, { "content": "This code finds where a number is in a list, removes one item, and inserts a new one.", "role": "assistant" } ]
[ { "content": "```python\ndef ask_numbers():\n total = 0\n for i in range(3):\n user_input = input(\"Enter a number: \")\n try:\n total += int(user_input)\n except ValueError:\n pass\n return total\n\nprint(ask_numbers())\n```", "role": "user" }, { "content": "This code asks the user for three numbers and adds them together.", "role": "assistant" } ]
[ { "content": "```python\ndef edit_list(values):\n updated = []\n for v in values:\n updated.append(v)\n if 3 in updated:\n updated.remove(3)\n updated.append(99)\n return updated\n\nprint(edit_list([1, 2, 3, 4]))\n```", "role": "user" }, { "content": "This code copies list items, removes the number 3, and adds 99 to the end.", "role": "assistant" } ]
[ { "content": "```python\nx = True or False\nresult = not x\n```", "role": "user" }, { "content": "This code shows how 'or' picks the first true value and how 'not' flips a boolean.", "role": "assistant" } ]
[ { "content": "```python\nis_day = True\nis_weekend = False\ncan_play = is_day and not is_weekend\nshould_study = not can_play\nprint(can_play, should_study)\n```", "role": "user" }, { "content": "This code uses booleans to decide whether you can play or should study based on the day and weekend status.", "role": "assistant" } ]
[ { "content": "```python\ncount = 0\nwhile count < 3:\n print(count)\n count += 1\nprint(\"Done!\")\n```", "role": "user" }, { "content": "This loop keeps counting up until the number reaches 3, showing how 'while' repeats actions.", "role": "assistant" } ]
[ { "content": "```python\ndef sum_to_int(a, b):\n x = int(a)\n y = int(b)\n total = x + y\n print(\"Sum:\", total)\n return total\n\nsum_to_int(\"3\", \"7\")\n```", "role": "user" }, { "content": "This function turns two strings into integers, adds them, prints the total, and returns it.", "role": "assistant" } ]
[ { "content": "```python\ndef text_tools(text):\n pos = text.find(\"a\")\n swapped = text.swapcase()\n replaced = text.replace(\"a\", \"*\")\n parts = text.split(\" \")\n joined = \"-\".join(parts)\n return pos, swapped, replaced, parts, joined\n\nprint(text_tools(\"Apples are Awesome\"))\n```", "role": "user" }, { "content": "This function uses several string methods to search, change cases, replace letters, split words, and join text with dashes.", "role": "assistant" } ]
[ { "content": "```python\nx = \"42\"\\nnum = int(x)\\ndef add_ten(n):\\n result = n + 10\\n return result\\nvalue = add_ten(num)\\nprint(value)\n```", "role": "user" }, { "content": "This code turns a string into an integer, adds 10 to it using a function, and prints the result.", "role": "assistant" } ]
[ { "content": "```python\nimport sys\\nprint(sys.version)\\nprint(sys.platform)\\nprint(len(sys.argv))\n```", "role": "user" }, { "content": "This code uses the sys module to show the Python version, the computer platform, and how many command‑line arguments were used.", "role": "assistant" } ]
[ { "content": "```python\ndef average_floats(values):\\n total = 0.0\\n count = 0\\n for v in values:\\n total += float(v)\\n count += 1\\n if count == 0:\\n return 0.0\\n return total / count\\nnums = [\"3.5\", \"2.0\", \"4.5\"]\\nprint(average_floats(nums))\n```", "role": "user" }, { "content": "This code turns strings into floats, adds them up, finds the average, and prints the result.", "role": "assistant" } ]
[ { "content": "```python\ndef compare_numbers(a, b):\\n if a > b:\\n return \"A is bigger\"\\n elif a < b:\\n return \"B is bigger\"\\n elif a == b:\\n return \"They are equal\"\\n else:\\n return \"Unknown\"\\nprint(compare_numbers(5, 3))\\nprint(compare_numbers(2, 7))\\nprint(compare_numbers(4, 4))\n```", "role": "user" }, { "content": "This code compares two numbers and uses elif to choose the correct message to return.", "role": "assistant" } ]
[ { "content": "```python\ntry:\\n x = int(\"hello\")\\nexcept ValueError:\\n print(\"That isn’t a number!\")\\ntry:\\n y = 5 + \"a\"\\nexcept TypeError:\\n print(\"You can’t add a number and a string!\")\n```", "role": "user" }, { "content": "This code shows how ValueError happens when converting bad input to int, and TypeError happens when using the wrong types together.", "role": "assistant" } ]
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
5