messages
listlengths
2
2
[ { "content": "```python\n# Large function about int()\ndef process_numbers(values):\n total = 0\n for v in values:\n num = int(v)\n if num % 2 == 0:\n total += num\n else:\n total -= num\n average = total / len(values)\n result = []\n for v in values:\n ...
[ { "content": "```python\n# Large function about int()\ndef convert_and_filter(values):\n converted = []\n for item in values:\n n = int(item)\n if n > 5:\n converted.append(n)\n else:\n converted.append(0)\n squared = []\n for c in converted:\n squar...
[ { "content": "```python\n# Small function about creating variables\ndef make_values():\n a = 5\n b = 10\n c = a + b\n d = c * 2\n e = d - a\n f = e / 3\n return f\n\nprint(make_values())\n```", "role": "user" }, { "content": "This code creates several variables, does math with t...
[ { "content": "```python\nmy_dict = {\"a\": 1, \"b\": 2}\nprint(my_dict[\"b\"])\n```", "role": "user" }, { "content": "This code makes a small dictionary and prints one value from it.", "role": "assistant" } ]
[ { "content": "```python\nx = 10\ny = x + 5\n```", "role": "user" }, { "content": "This code creates two variables and sets the second one to be larger than the first.", "role": "assistant" } ]
[ { "content": "```python\n# Large function using def and return\n\ndef analyze_numbers(nums):\n total = 0\n count = 0\n for n in nums:\n total += n\n count += 1\n average = total / count\n highest = max(nums)\n lowest = min(nums)\n summary = {\n \"total\": total,\n ...
[ { "content": "```python\n# String method function\n\ndef fix_name(text):\n lower = text.lower()\n upper = text.upper()\n title = text.title()\n cap = text.capitalize()\n return lower, upper, title, cap\n\nprint(fix_name(\"hELlo WoRLd\"))\n```", "role": "user" }, { "content": "This cod...
[ { "content": "```python\n# int() example function\n\ndef convert_to_int(value):\n number = int(value)\n doubled = number * 2\n return doubled\n\nprint(convert_to_int(\"6\"))\n```", "role": "user" }, { "content": "This code turns a string into an integer and doubles it.", "role": "assist...
[ { "content": "```python\n# Exceptions: TypeError and ValueError\n\ntry:\n x = int(\"hello\")\nexcept ValueError:\n print(\"ValueError: cannot turn text into a number\")\n\ntry:\n y = \"a\" + 5\nexcept TypeError:\n print(\"TypeError: cannot add text and number\")\n```", "role": "user" }, { ...
[ { "content": "```python\n# if/else example\n\nage = 12\nprint(\"Child\" if age < 13 else \"Teen or adult\")\n```", "role": "user" }, { "content": "This code prints one message if the age is small and another if it is bigger.", "role": "assistant" } ]
[ { "content": "```python\nimport math as m\nfrom math import sqrt\n```", "role": "user" }, { "content": "This code shows how to rename a module with 'as' and import a specific function using 'from'.", "role": "assistant" } ]
[ { "content": "```python\nmy_list = [\"apple\", \"banana\", \"cherry\"]\ndef remove_item(item):\n if item in my_list:\n my_list.remove(item)\n return my_list\n else:\n return \"Item not found\"\nresult = remove_item(\"banana\")\nprint(result)\n```", "role": "user" }, { "con...
[ { "content": "```python\nimport sys\nprint(sys.version)\n```", "role": "user" }, { "content": "This code prints the version of Python you’re using.", "role": "assistant" } ]
[ { "content": "```python\nimport sys\ndef show_sys_info():\n print(\"Python version:\\n\" + sys.version)\n print(\"Executable:\\n\" + sys.executable)\n print(\"Platform:\\n\" + sys.platform)\n print(\"Path:\")\n for p in sys.path:\n print(p)\n print(\"Arguments:\")\n for arg in sys.ar...
[ { "content": "```python\nx = \"3.14\"\ny = float(x)\nprint(y)\nprint(y * 2)\nprint(type(y))\n```", "role": "user" }, { "content": "This code shows how float() changes a string into a number you can do math with.", "role": "assistant" } ]
[ { "content": "```python\\nimport math\\nresult = math.sqrt(25)\\nprint(result)\\n```", "role": "user" }, { "content": "This code imports the math module and uses it to find the square root of 25.", "role": "assistant" } ]
[ { "content": "```python\\nimport random\\ndef pick_number():\\n nums = [1, 2, 3, 4, 5]\\n choice = random.choice(nums)\\n print(\"Picked:\", choice)\\n return choice\\npick_number()\\n```", "role": "user" }, { "content": "This code imports the random module and makes a function that pick...
[ { "content": "```python\\nx = 5\\nprint(\"big\" if x > 10 else \"small\")\\n```", "role": "user" }, { "content": "This code checks if x is greater than 10, using a quick if-else expression.", "role": "assistant" } ]
[ { "content": "```python\\ndef summarize_lengths(words):\\n total = len(words)\\n for w in words:\\n print(w, \"has\", len(w), \"letters\")\\n print(\"Total words:\", total)\\n if total > 3:\\n print(\"That's a lot of words!\")\\n else:\\n print(\"That's only a few words.\")\\...
[ { "content": "```python\\nnums = [3, 6, 9]\\nnums.insert(1, 4); popped = nums.pop(); idx = nums.index(4)\\n```", "role": "user" }, { "content": "This code inserts a number, removes the last number, and finds the index of a value in the list.", "role": "assistant" } ]
[ { "content": "```python\nclass Dog:\\n def __init__(self, name): self.name = name\\n def __str__(self): return self.name\n```", "role": "user" }, { "content": "This code creates a Dog class that sets a name and returns it when printed.", "role": "assistant" } ]
[ { "content": "```python\nprint(5 == 5)\\nprint(\"hi\" == \"bye\")\n```", "role": "user" }, { "content": "This code compares values to check if they are equal.", "role": "assistant" } ]
[ { "content": "```python\ndef count_vowels(text):\\n vowels = \"aeiou\"\\n total = 0\\n for char in text:\\n if char.lower() in vowels:\\n total += 1\\n return total\\n\\nword = \"Education\"\\nprint(count_vowels(word))\n```", "role": "user" }, { "content": "This code de...
[ { "content": "```python\nimport math\\nprint(math.sqrt(16))\n```", "role": "user" }, { "content": "This code imports a math tool and uses it to find a square root.", "role": "assistant" } ]
[ { "content": "```python\ndef manage_scores():\\n scores = {\"A\": 90, \"B\": 80}\\n for k in scores.keys(): print(k)\\n for v in scores.values(): print(v)\\n for i in scores.items(): print(i)\\n scores.update({\"C\": 70})\\n removed = scores.pop(\"A\")\\n print(\"Removed:\", removed)\\n ...
[ { "content": "```python\nclass Pet:\n def __init__(self, name):\n self.name = name\n def __str__(self):\n return \"Pet's name is \" + self.name\nmy_pet = Pet(\"Buddy\")\nprint(my_pet)\n```", "role": "user" }, { "content": "This code creates a simple class with two special methods...
[ { "content": "```python\nnums = [4, 7, 9]\npos = nums.index(7)\nnums.pop(1)\nnums.insert(1, 10)\nprint(pos)\nprint(nums)\n```", "role": "user" }, { "content": "This code finds where a value is located, removes an item from that spot, and adds a new value back into the list.", "role": "assistant"...
[ { "content": "```python\ncolors = [\"red\", \"blue\"]\ncolors.append(\"green\")\ncolors.remove(\"blue\")\nprint(colors)\n```", "role": "user" }, { "content": "This code adds a new item to the end of a list and removes one item by name.", "role": "assistant" } ]
[ { "content": "```python\nx = 12\nif x > 10:\n print(\"Big number\")\nelse:\n print(\"Small number\")\n```", "role": "user" }, { "content": "This code checks a condition and prints one message if it’s true and another if it’s not.", "role": "assistant" } ]
[ { "content": "```python\nnums = [1, 2, 3, 4, 5]\nprint(nums[1:4])\n```", "role": "user" }, { "content": "This code prints a slice of the list, showing only part of it.", "role": "assistant" } ]
[ { "content": "```python\nimport random\nx = random.randint(1, 10)\ny = random.choice([\"red\", \"blue\", \"green\"])\nprint(x, y)\n```", "role": "user" }, { "content": "This code uses the random module to pick a random number and a random color.", "role": "assistant" } ]
[ { "content": "```python\ndef convert_to_int(value):\n try:\n num = int(value)\n print(\"Converted:\", num)\n return num\n except ValueError:\n print(\"Not a number!\")\n return None\n\nconvert_to_int(\"42\")\n```", "role": "user" }, { "content": "This code tr...
[ { "content": "```python\nclass Dog:\n def __init__(self, name):\n self.name = name\n def __str__(self):\n return \"Dog named \" + self.name\n\nd = Dog(\"Buddy\")\nprint(d)\n```", "role": "user" }, { "content": "This code makes a Dog class that sets a name and prints a friendly me...
[ { "content": "```python\nimport sys\nprint(sys.version)\nprint(sys.platform)\n```", "role": "user" }, { "content": "This code shows the Python version and what system the computer is running.", "role": "assistant" } ]
[ { "content": "```python\nimport math\nprint(math.pi)\n```", "role": "user" }, { "content": "This code imports a module and uses it to print the value of pi.", "role": "assistant" } ]
[ { "content": "```python\nimport sys\nprint(sys.version)\nprint(len(sys.argv))\nprint(sys.platform)\n```", "role": "user" }, { "content": "This code shows information about your Python system, like the version you're using, how many command-line arguments were given, and what type of computer system ...
[ { "content": "```python\na = 5\nb = 3\nprint(a != b)\nprint(a > b)\nprint(a <= b)\nprint(a >= 5)\n```", "role": "user" }, { "content": "This code compares two numbers using different comparison symbols to check if values are equal, bigger, smaller, or not equal.", "role": "assistant" } ]
[ { "content": "```python\nimport sys\nprint(sys.executable)\n```", "role": "user" }, { "content": "This code prints the path of the Python program your computer is using.", "role": "assistant" } ]
[ { "content": "```python\nx = 10\nprint(\"big\" if x > 5 else \"small\")\n```", "role": "user" }, { "content": "This code checks a number and prints one message if it's big and another if it's small.", "role": "assistant" } ]
[ { "content": "```python\ndef string_tools(text):\n pos = text.find('a')\n swapped = text.swapcase()\n pieces = text.split(' ')\n joined = '-'.join(pieces)\n replaced = text.replace('a', '@')\n print('First a at:', pos)\n print('Swapcase:', swapped)\n print('Split words:', pieces)\n pr...
[ { "content": "```python\nfrom math import sqrt as square_root\n\ndef process_numbers(nums):\n results = []\n for n in nums:\n if n >= 0:\n r = square_root(n)\n results.append(r)\n else:\n results.append(None)\n return results\n\nvalues = [4, 9, -1, 16]\npr...
[ { "content": "```python\nnums = [1, 2, 3, 4]\n\ndef double(x):\n return x * 2\n\nresult = list(map(double, nums))\nprint(result)\n```", "role": "user" }, { "content": "This code uses map to apply a function that doubles numbers.", "role": "assistant" } ]
[ { "content": "```python\ndef filter_values(values):\n kept = []\n for v in values:\n if (v > 10 or v == 5) and not (v < 0):\n kept.append(v)\n else:\n pass\n return kept\n\nnums = [5, 12, -3, 8, 15]\nprint(filter_values(nums))\n```", "role": "user" }, { "...
[ { "content": "```python\na = 10\nb = 20\nc = a + b\n\ndef show_total():\n print(c)\n\nshow_total()\n```", "role": "user" }, { "content": "This code shows how variables store values and can be used in math.", "role": "assistant" } ]
[ { "content": "```python\nwords = [\"cat\", \"bird\", \"lion\"]\n\ndef list_length(x):\n return len(x)\n\nprint(list_length(words))\n```", "role": "user" }, { "content": "This code shows how len counts how many items are in a list.", "role": "assistant" } ]
[ { "content": "```python\ncount = 0\nwhile count < 5:\n print(\"Counting:\", count)\n count += 1\n\nnumber = 10\nwhile number > 0:\n print(\"Number is:\", number)\n number -= 2\n\nx = 3\ny = 0\nwhile y < x:\n print(\"y is\", y)\n y += 1\n```", "role": "user" }, { "content": "This co...
[ { "content": "```python\nname = \"Alex\"\nlength = len(name)\nprint(length)\n\nnumbers = [1, 2, 3]\nprint(len(numbers))\n```", "role": "user" }, { "content": "This code shows how len() counts how many items are in a string or list.", "role": "assistant" } ]
[ { "content": "```python\ndef show_messages():\n print(\"Starting messages...\")\n for i in range(5):\n print(\"Message number:\", i)\n print(\"Loop finished!\")\n text = \"Hello\"\n print(\"The word is:\", text)\n print(\"Done printing.\")\n\nshow_messages()\n```", "role": "user" ...
[ { "content": "```python\ndef compare_values(a, b):\n if a == b:\n return \"They are equal\"\n else:\n return \"They are not equal\"\n\nprint(compare_values(3, 3))\nprint(compare_values(4, 5))\n```", "role": "user" }, { "content": "This code checks if two values are the same using...
[ { "content": "```python\ndef check_types(values):\n for v in values:\n if isinstance(v, int):\n print(v, \"is an integer\")\n elif isinstance(v, str):\n print(v, \"is a string\")\n elif isinstance(v, float):\n print(v, \"is a float\")\n else:\n ...
[ { "content": "```python\nx = 7\nif x < 5:\n print(\"Small\")\nelif x < 10:\n print(\"Medium\")\nelse:\n print(\"Large\")\n```", "role": "user" }, { "content": "This code checks different ranges and uses elif to pick the correct message.", "role": "assistant" } ]
[ { "content": "```python\nstudent = {\"name\": \"Amy\", \"age\": 12}\nprint(student[\"name\"])\n```", "role": "user" }, { "content": "This code uses a dictionary to store information and prints one of the values.", "role": "assistant" } ]
[ { "content": "```python\ndef apply_operations(numbers):\n add_two = lambda x: x + 2\n multiply_three = lambda x: x * 3\n results = []\n for n in numbers:\n a = add_two(n)\n m = multiply_three(a)\n results.append(m)\n return results\n\nvals = [1, 2, 3, 4]\nprint(apply_operatio...
[ { "content": "```python\nnum = float(\"3.5\")\nprint(num)\n```", "role": "user" }, { "content": "This code turns a string into a decimal number.", "role": "assistant" } ]
[ { "content": "```python\nclass Robot:\n def __init__(self):\n self.__secret_code = 42\n def show(self):\n print(self.__secret_code)\n def __hidden(self):\n print(\"Hidden method!\")\n```", "role": "user" }, { "content": "This code uses double underscores to make some pa...
[ { "content": "```python\ndef compare_numbers(a, b):\n if a == b:\n return \"They are equal\"\n else:\n return \"They are not equal\"\n\nprint(compare_numbers(5, 5))\nprint(compare_numbers(3, 7))\n```", "role": "user" }, { "content": "This code checks whether two numbers are the s...
[ { "content": "```python\nage = 12\nname = \"Sam\"\n```", "role": "user" }, { "content": "This code creates a number variable and a word variable.", "role": "assistant" } ]
[ { "content": "```python\npets = [\"cat\", \"dog\", \"fish\"]\npets.remove(\"dog\")\n```", "role": "user" }, { "content": "This code removes an item from a list.", "role": "assistant" } ]
[ { "content": "```python\ndef check_temperature(temp):\n if temp > 75:\n return \"It's warm\"\n else:\n return \"It's cool\"\n\nprint(check_temperature(80))\nprint(check_temperature(60))\n```", "role": "user" }, { "content": "This code uses if/else to decide if the temperature is ...
[ { "content": "```python\nmessage = \"Hello\" + \" World\"\nprint(message)\n```", "role": "user" }, { "content": "This code joins two strings together and prints them.", "role": "assistant" } ]
[ { "content": "```python\n# Dictionary methods example\ninfo = {\"name\": \"Alex\", \"age\": 12}\nvalue = info.get(\"grade\", \"No grade found\")\nmessage = \"Student {0} is {1} years old.\".format(info[\"name\"], info[\"age\"])\nprint(value)\nprint(message)\n```", "role": "user" }, { "content": "Thi...
[ { "content": "```python\n# OR and NOT operators example\nstatus = \"open\"\nlocked = False\nallowed = True\nif (status == \"open\" or not locked) and allowed:\n print(\"You may enter.\")\nelse:\n print(\"Entry denied.\")\n```", "role": "user" }, { "content": "This code checks door conditions u...
[ { "content": "```python\nnums = [3, 1, 2]\ncopy_nums = nums.copy()\nnums.extend([5, 4])\nnums.sort()\nnums.reverse()\ncount_twos = nums.count(2)\nnums.clear()\n```", "role": "user" }, { "content": "This code shows list methods for copying, adding, sorting, reversing, counting, and clearing items.", ...
[ { "content": "```python\n# OR and NOT in a function\n\ndef check_weather(sunny, raining):\n if sunny or not raining:\n return \"Go outside!\"\n else:\n return \"Stay inside.\"\n\nprint(check_weather(True, False))\n```", "role": "user" }, { "content": "This code uses OR and NOT in...
[ { "content": "```python\n# import keyword example\nimport math\n\ndef area_circle(r):\n return math.pi * r * r\n\nprint(area_circle(3))\n```", "role": "user" }, { "content": "This code uses import to bring in the math module so it can calculate a circle’s area.", "role": "assistant" } ]
[ { "content": "```python\ndef process_numbers(nums):\\n total = 0\\n count = 0\\n for n in nums:\\n total += n\\n count += 1\\n average = total / count\\n maximum = max(nums)\\n minimum = min(nums)\\n result = {\"total\": total, \"average\": average, \"max\": maximum, \"min\": ...
[ { "content": "```python\nvalue = float(\"3.14\")\\nprint(value)\n```", "role": "user" }, { "content": "This code turns a string into a decimal number and prints it.", "role": "assistant" } ]
[ { "content": "```python\ndef create_profile(name, age):\\n username = name.lower()\\n birth_year = 2025 - age\\n is_adult = age >= 18\\n greeting = \"Hello, \" + name\\n profile = {}\\n profile[\"username\"] = username\\n profile[\"birth_year\"] = birth_year\\n profile[\"is_adult\"] = is...
[ { "content": "```python\nclass Example:\\n def __secret(self):\\n return \"hidden\"\\n def reveal(self):\\n return self.__secret()\n```", "role": "user" }, { "content": "This code shows a private method that can only be used inside the class.", "role": "assistant" } ]
[ { "content": "```python\nfrom math import sqrt as root\\nprint(root(16))\n```", "role": "user" }, { "content": "This code imports a function using from and renames it with as.", "role": "assistant" } ]
[ { "content": "```python\nfunction_output = []\nfor i in range(1, 11):\n text = str(i)\n function_output.append(text)\n\nfor j in range(5, 16):\n text = str(j * 2)\n function_output.append(text)\n\nfor item in function_output:\n print(\"Value: \" + item)\n\nprint(\"Total items: \" + str(len(functi...
[ { "content": "```python\nnums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\nfirst_half = nums[:5]\nsecond_half = nums[5:]\nstep_list = nums[::2]\nreversed_list = nums[::-1]\nmid_section = nums[2:8:2]\n\nprint(first_half)\nprint(second_half)\nprint(step_list)\nprint(reversed_list)\nprint(mid_section)\n```", "role": "us...
[ { "content": "```python\na = 10\nb = 20\nresults = []\n\nresults.append(a != b)\nresults.append(a > b)\nresults.append(a >= b)\nresults.append(a < b)\nresults.append(a <= b)\n\nfor r in results:\n print(\"Result:\", r)\n\nif a < b:\n print(\"a is smaller than b\")\nelse:\n print(\"a is not smaller than...
[ { "content": "```python\ninfo = {\"name\": \"Alex\", \"age\": 12}\nname_value = info.get(\"name\")\nage_value = info.get(\"age\")\nmessage = \"Student {} is {} years old.\".format(name_value, age_value)\nprint(message)\n```", "role": "user" }, { "content": "This code uses .get() to safely read value...
[ { "content": "```python\nprint(3 in [1,2,3,4])\nprint('a' in 'cat')\n```", "role": "user" }, { "content": "This code checks whether an item is inside a list or a string using the in operator.", "role": "assistant" } ]
[ { "content": "```python\n# Working with a dictionary\nstudent_scores = {\"Alice\": 90, \"Bob\": 85, \"Charlie\": 92}\n\n# Add a new score\nstudent_scores[\"Diana\"] = 88\n\n# Update a score\nstudent_scores[\"Bob\"] = 89\n\n# Remove a student\nremoved = student_scores.pop(\"Alice\")\n\n# Loop and print\nfor name...
[ { "content": "```python\nage = -3\nif age < 0:\n raise ValueError(\"Age cannot be negative!\")\n```", "role": "user" }, { "content": "This code checks if an age is negative and raises an error if it is.", "role": "assistant" } ]
[ { "content": "```python\nwords = [\"cat\", \"dog\", \"hamster\"]\nlength = len(words)\nprint(length)\n```", "role": "user" }, { "content": "This code uses len() to count how many items are in a list.", "role": "assistant" } ]
[ { "content": "```python\nmy_list = [3, 1, 2]\ncopy_list = my_list.copy(); my_list.extend([4, 5]); my_list.sort(); copy_list.clear(); my_list.reverse(); count_twos = my_list.count(2)\n```", "role": "user" }, { "content": "This code shows different list methods like copying, sorting, clearing, and cou...
[ { "content": "```python\n# Using 'as' and 'from' in a function\nimport math as m\n\ndef calculate_values(x):\n try:\n result = m.sqrt(x)\n return result\n except Exception as e:\n raise ValueError(\"Cannot calculate square root\") from e\n\nprint(calculate_values(16))\n```", "role...
[ { "content": "```python\nmy_list = [1, 2, 3, 4]\ndef show_length(lst):\n length = len(lst)\n print(\"The list has\", length, \"items\")\n return length\nresult = show_length(my_list)\nprint(result)\n```", "role": "user" }, { "content": "This code uses len() to count how many items are in a ...
[ { "content": "```python\nis_big = 10 > 5\nprint(is_big)\n```", "role": "user" }, { "content": "This code checks if 10 is greater than 5 and prints the boolean result.", "role": "assistant" } ]
[ { "content": "```python\ndef check_number(n):\n if n > 0:\n print(\"Positive\")\n else:\n print(\"Not positive\")\ncheck_number(3)\ncheck_number(-1)\n```", "role": "user" }, { "content": "This code uses an if/else statement to tell whether a number is positive.", "role": "ass...
[ { "content": "```python\nfruits = [\"apple\", \"banana\", \"orange\"]\nprint(\"apple\" in fruits)\nprint(\"grape\" in fruits)\nprint(\"orange\" in fruits)\n```", "role": "user" }, { "content": "This code checks whether certain words are inside a list of fruits.", "role": "assistant" } ]
[ { "content": "```python\nnum = int(\"5\")\nprint(num)\n```", "role": "user" }, { "content": "This code changes the string \"5\" into an integer and prints it.", "role": "assistant" } ]
[ { "content": "```python\nx = 5\nif x > 3 and not (x < 0):\n print(\"x is positive and greater than 3\")\nelif x < 3 or x == 3:\n print(\"x is 3 or less\")\n```", "role": "user" }, { "content": "This code checks a number using and, or, and not to decide which message to print.", "role": "as...
[ { "content": "```python\nname = \"Alex\"\\nprint(name.upper())\n```", "role": "user" }, { "content": "This code stores a word and prints it in all capital letters.", "role": "assistant" } ]
[ { "content": "```python\ndef dictionary_demo():\n info = {\"name\": \"Sam\", \"age\": 12}\n for key, value in info.items():\n print(key, value)\n print(list(info.keys()))\n print(list(info.values()))\n info.update({\"grade\": \"7th\"})\n info.pop(\"age\")\n return info\n```", "ro...
[ { "content": "```python\nx = 10 # this stores a number\nprint(x) # this shows the number\n```", "role": "user" }, { "content": "This code uses # to add comments explaining what each line does.", "role": "assistant" } ]
[ { "content": "```python\nimport math\nimport random\n\ndef number_tools(n):\n squared = math.pow(n, 2)\n root = math.sqrt(n)\n rnd = random.randint(1, 10)\n total = squared + root + rnd\n print(\"Squared:\", squared)\n print(\"Square root:\", root)\n print(\"Random number:\", rnd)\n retu...
[ { "content": "```python\nclass Pet:\n def __init__(self, name): self.name = name\n def __str__(self): return f\"Pet: {self.name}\"\nprint(str(Pet(\"Milo\")))\n```", "role": "user" }, { "content": "This code creates a pet object and prints its name using built‑in methods that run automatically....
[ { "content": "```python\ndef show_lines():\n text = \"Line 1\\nLine 2\\nLine 3\"\n for line in text.split(\"\\n\"):\n print(line)\nshow_lines()\n```", "role": "user" }, { "content": "This code uses the newline character to split text into lines and print them one by one.", "role": "...
[ { "content": "```python\ndef combine_strings_and_list(words, extra):\n result = []\n for w in words:\n phrase = w + \" \" + extra\n result.append(phrase)\n long_string = \"\\n\".join(result)\n return long_string, result\nwords = [\"Learn\", \"Practice\", \"Master\"]\nextra = \"Python\"...
[ { "content": "```python\ndef double_values(nums):\n doubled = list(map(lambda x: x * 2, nums))\n return doubled\nprint(double_values([1, 2, 3, 4]))\n```", "role": "user" }, { "content": "This code uses map to double each number in a list.", "role": "assistant" } ]
[ { "content": "```python\ninfo = {\"name\": \"Ava\", \"age\": 12}\nprint(info.keys(), info.values(), info.items()); info.update({\"age\": 13}); info.pop(\"name\")\n```", "role": "user" }, { "content": "This code shows a dictionary’s keys, values, and items, then updates and removes data.", "role"...
[ { "content": "```python\nnums = [1, 2, 3]\nsquares = list(map(lambda x: x * 2, nums))\nprint(squares)\n```", "role": "user" }, { "content": "This code uses map to double each number in a list and prints the new list.", "role": "assistant" } ]
[ { "content": "```python\nclass Example:\n def __init__(self, x):\n self.x = x\n def __secret(self):\n return self.x * 2\n def reveal(self):\n return self.__secret()\nprint(Example(5).reveal())\n```", "role": "user" }, { "content": "This code shows how double underscores...
[ { "content": "```python\nimport sys\n\ndef show_sys_info():\n print(sys.version)\n print(sys.executable)\n print(sys.platform)\n for path in sys.path:\n print(path)\n print(len(sys.argv))\n for arg in sys.argv:\n print(arg)\n\nshow_sys_info()\n```", "role": "user" }, { ...
[ { "content": "```python\n\ndef string_tools(text):\n print(text.upper())\n print(text.lower())\n print(text.capitalize())\n print(len(text))\n for char in text:\n print(char)\n words = text.split()\n for w in words:\n print(w)\n print(\"-\".join(words))\n print(text.repl...
[ { "content": "```python\n\ndef join_lists(a, b):\n combined = a + b\n text = \"List A: \" + str(a) + \", List B: \" + str(b)\n print(text)\n print(combined)\n\njoin_lists([1,2], [3,4])\n```", "role": "user" }, { "content": "This code adds two lists together and also shows how to join tex...