messages listlengths 2 2 |
|---|
[
{
"content": "```python\ndef grade_score(score):\\n if score >= 90:\\n result = \"A\"\\n elif score >= 80:\\n result = \"B\"\\n elif score >= 70:\\n result = \"C\"\\n elif score >= 60:\\n result = \"D\"\\n else:\\n result = \"F\"\\n if result in [\"A\", \"B\"... |
[
{
"content": "```python\nclass Pet:\\n def __init__(self, name):\\n self.name = name\\n def speak(self):\\n return self.name + \" says hi!\"\\nmy_pet = Pet(\"Milo\")\\nresult = my_pet.speak()\n```",
"role": "user"
},
{
"content": "This code creates a simple class for a pet and le... |
[
{
"content": "```python\ndef is_even(num):\\n check = (num % 2 == 0)\\n if check:\\n return True\\n else:\\n return False\\nresult = is_even(7)\n```",
"role": "user"
},
{
"content": "This code uses a boolean check to see if a number is even.",
"role": "assistant"
}
] |
[
{
"content": "```python\ndef sum_list(numbers):\\n total = 0\\n for n in numbers:\\n total += n\\n return total\\nanswer = sum_list([1,2,3,4])\n```",
"role": "user"
},
{
"content": "This code uses a for loop to add up all numbers in a list.",
"role": "assistant"
}
] |
[
{
"content": "```python\ntext = \"Hello\"\\nlonger = text + \" world\"\\nupper = longer.upper()\\nprint(upper)\n```",
"role": "user"
},
{
"content": "This code works with strings by joining them and changing letters to uppercase.",
"role": "assistant"
}
] |
[
{
"content": "```python\nclass Example:\n def __init__(self):\n self.x = 5\n def __private_method(self):\n return self.x * 2\n```",
"role": "user"
},
{
"content": "This code shows how double underscores hide a method so it can only be used inside the class.",
"role": "assista... |
[
{
"content": "```python\nimport sys\n\ndef show_info():\n print(sys.version)\n print(sys.platform)\n print(sys.argv)\n print(len(sys.argv))\n for arg in sys.argv:\n print(arg)\n return sys.getsizeof(sys.version)\n```",
"role": "user"
},
{
"content": "This code uses the sys m... |
[
{
"content": "```python\nfrom math import sqrt as square_root\nx = 9\ny = square_root(x)\nprint(y)\n```",
"role": "user"
},
{
"content": "This code uses from and as to import a math function with a shorter name.",
"role": "assistant"
}
] |
[
{
"content": "```python\ndef convert_and_sum(values):\n total = 0.0\n for v in values:\n try:\n num = float(v)\n total += num\n except ValueError:\n print(\"Skipping:\", v)\n print(\"Total:\", total)\n return total\n\nnums = [\"3.2\", \"5\", \"hi\", \"7... |
[
{
"content": "```python\nclass Animal:\n def __init__(self, name):\n self.name = name\n def speak(self):\n print(self.name + \" makes a sound\")\n```",
"role": "user"
},
{
"content": "This code creates a class that lets you make objects with names and a simple speak action.",
... |
[
{
"content": "```python\nfor i in range(1, 6):\n total = 0\n for j in range(1, i + 1):\n total += j\n print(\"Sum from 1 to\", i, \"is\", total)\n\nnumbers = [2, 4, 6, 8, 10]\nfor n in numbers:\n square = n * n\n print(\"Square of\", n, \"is\", square)\n\nfor letter in \"HELLO\":\n prin... |
[
{
"content": "```python\ndef count_vowels(text):\n vowels = \"aeiou\"\n count = 0\n for char in text:\n if char.lower() in vowels:\n count += 1\n return count\n\nprint(count_vowels(\"Hello World\"))\n```",
"role": "user"
},
{
"content": "This code counts how many vowels... |
[
{
"content": "```python\nitems = [\"apple\", \"banana\", \"cherry\"]\nitems.remove(\"banana\")\n```",
"role": "user"
},
{
"content": "This code removes an item from a list.",
"role": "assistant"
}
] |
[
{
"content": "```python\nname = \"Alice\"\nprint(name.upper())\n```",
"role": "user"
},
{
"content": "This code turns a string into uppercase letters.",
"role": "assistant"
}
] |
[
{
"content": "```python\ndef create_variables():\n age = 12\n name = \"Sam\"\n height = 1.55\n is_student = True\n favorite_colors = [\"blue\", \"green\"]\n score = 0\n for i in range(5):\n score += i\n info = name + \" is \" + str(age) + \" years old.\"\n print(info)\n prin... |
[
{
"content": "```python\nimport math\nprint(math.sqrt(16))\n```",
"role": "user"
},
{
"content": "This code imports the math module and prints the square root of 16.",
"role": "assistant"
}
] |
[
{
"content": "```python\ns = \"Hello\"\nprint(s + \" World\")\n```",
"role": "user"
},
{
"content": "This code makes a string and prints it combined with another string.",
"role": "assistant"
}
] |
[
{
"content": "```python\ndef add_numbers(a, b):\n total = a + b\n print(\"Adding numbers...\")\n return total\n\nresult = add_numbers(3, 4)\nprint(result)\n```",
"role": "user"
},
{
"content": "This code defines a function that adds two numbers and returns the answer.",
"role": "assista... |
[
{
"content": "```python\ndef list_to_string(nums):\n result = \"\"\n for i in range(len(nums)):\n result += str(nums[i])\n if i < len(nums) - 1:\n result += \", \"\n print(\"Converted list to string:\")\n return result\n\nprint(list_to_string([1, 2, 3, 4]))\n```",
"role"... |
[
{
"content": "```python\nimport sys\n\ndef show_args():\n print(\"Arguments passed:\")\n for arg in sys.argv:\n print(arg)\n\nshow_args()\n```",
"role": "user"
},
{
"content": "This code uses the sys module to show the arguments given when the program runs.",
"role": "assistant"
}... |
[
{
"content": "```python\ndef describe_pet():\n info = {\"name\": \"Buddy\", \"type\": \"dog\"}\n pet_name = info.get(\"name\", \"Unknown\")\n pet_type = info.get(\"type\", \"Unknown\")\n message = \"This is {} the {}.\".format(pet_name, pet_type)\n print(message)\n\ndescribe_pet()\n```",
"rol... |
[
{
"content": "```python\ndef greet_user():\n name = input(\"Enter your name: \")\n print(\"Hello, \" + name + \"!\")\n\ngreet_user()\n```",
"role": "user"
},
{
"content": "This code asks the user for their name and then prints a greeting.",
"role": "assistant"
}
] |
[
{
"content": "```python\nprint(isinstance(5, int))\nprint(isinstance(\"hello\", str))\n```",
"role": "user"
},
{
"content": "This code checks if values are certain types, like numbers or strings.",
"role": "assistant"
}
] |
[
{
"content": "```python\ndef divide_numbers(a, b):\n try:\n if not isinstance(a, (int, float)) or not isinstance(b, (int, float)):\n raise TypeError(\"Both arguments must be numbers\")\n result = a / b\n return result\n except ZeroDivisionError:\n print(\"You can't d... |
[
{
"content": "```python\ndef read_file():\n with open(\"example.txt\", \"r\") as f:\n text = f.read()\n print(text)\n\nread_file()\n```",
"role": "user"
},
{
"content": "This code opens a file safely using with and prints its contents.",
"role": "assistant"
}
] |
[
{
"content": "```python\n# Working with tuples in a large function\n\ndef analyze_scores():\n scores = (88, 92, 79, 85, 90)\n highest = max(scores)\n lowest = min(scores)\n total = sum(scores)\n average = total / len(scores)\n print(\"Scores:\", scores)\n print(\"Highest:\", highest)\n p... |
[
{
"content": "```python\n# Deleting an item from a list\nfruits = [\"apple\", \"banana\", \"orange\"]\nfruits.remove(\"banana\")\nprint(fruits)\n```",
"role": "user"
},
{
"content": "This code makes a list of fruits, removes one item, and prints the new list.",
"role": "assistant"
}
] |
[
{
"content": "```python\nclass Pet:\n def __init__(self, name): self.name = name\n def __str__(self): return f\"Pet name: {self.name}\"\n```",
"role": "user"
},
{
"content": "This code shows how __init__ sets up a new object and __str__ controls how it is printed.",
"role": "assistant"
}... |
[
{
"content": "```python\n# Large class example\nclass Robot:\n def __init__(self, name, battery):\n self.name = name\n self.battery = battery\n def charge(self, amount):\n self.battery += amount\n print(self.name, \"charged to\", self.battery)\n def work(self):\n if s... |
[
{
"content": "```python\n# String method examples\n\ndef show_string_changes(text):\n print(text.lower())\n print(text.upper())\n print(text.title())\n print(text.capitalize())\n print(\"Original:\", text)\n\nshow_string_changes(\"hELlo worLD\")\n```",
"role": "user"
},
{
"content": "... |
[
{
"content": "```python\nimport random\\nprint(random.random())\n```",
"role": "user"
},
{
"content": "This code uses Python's random module to print a random number between 0 and 1.",
"role": "assistant"
}
] |
[
{
"content": "```python\ndef slice_demo(lst):\\n first_half = lst[:len(lst)//2]\\n second_half = lst[len(lst)//2:]\\n middle_section = lst[2:5]\\n reversed_list = lst[::-1]\\n every_other = lst[::2]\\n print(first_half)\\n print(second_half)\\n print(middle_section)\\n print(reversed_... |
[
{
"content": "```python\nx = int(\"42\")\\ny = int(3.9)\\nprint(x + y)\n```",
"role": "user"
},
{
"content": "This code turns a string and a decimal number into whole numbers, then adds them together.",
"role": "assistant"
}
] |
[
{
"content": "```python\ndef ask_numbers():\\n total = 0\\n count = 0\\n while True:\\n user_input = input(\"Enter a number or 'stop': \")\\n if user_input == \"stop\":\\n break\\n num = int(user_input)\\n total += num\\n count += 1\\n print(\"You typed\... |
[
{
"content": "```python\nimport sys\\nprint(sys.version)\\nprint(sys.argv)\\nprint(sys.platform)\n```",
"role": "user"
},
{
"content": "This code uses the sys module to show the Python version, the command-line arguments, and the system type.",
"role": "assistant"
}
] |
[
{
"content": "```python\nclass Animal:\\n def __init__(self, name):\\n self.name = name\\n def speak(self):\\n print(self.name + \" makes a sound\")\n```",
"role": "user"
},
{
"content": "This code creates a simple class with a name and a method that prints a message.",
"role... |
[
{
"content": "```python\ndef list_strings(start, end):\\n result = []\\n for num in range(start, end):\\n text = str(num)\\n result.append(text)\\n for item in result:\\n print(\"Number as text:\", item)\\n return result\\n\\nlist_strings(1, 10)\n```",
"role": "user"
},
... |
[
{
"content": "```python\ninfo = {\"name\": \"Alex\", \"age\": 12}\\nprint(info.items())\\nprint(info.keys())\\nprint(info.values())\\ninfo.update({\"grade\": 7})\\ninfo.pop(\"age\")\n```",
"role": "user"
},
{
"content": "This code shows ways to read and change a dictionary using its built‑in methods... |
[
{
"content": "```python\ndef add_numbers(a, b):\\n # This function adds two numbers\\n result = a + b\\n # Print the result\\n print(\"Sum:\", result)\\n # Return the sum\\n return result\\n\\nadd_numbers(3, 5)\n```",
"role": "user"
},
{
"content": "This code shows how comments exp... |
[
{
"content": "```python\nimport time\\nprint(\"Starting...\")\\ntime.sleep(2)\\nprint(\"Done waiting!\")\\ncurrent = time.time()\\nprint(current)\n```",
"role": "user"
},
{
"content": "This code uses the time module to pause the program and show the current time.",
"role": "assistant"
}
] |
[
{
"content": "```python\n# This function adds two numbers\n# and returns the result\n\ndef add_numbers(a, b):\n # add the numbers\n result = a + b\n # return the answer\n return result\n```",
"role": "user"
},
{
"content": "This code shows how comments explain what each line does so peop... |
[
{
"content": "```python\n# This function removes a chosen item from a list\n\ndef remove_item(my_list, item):\n if item in my_list:\n my_list.remove(item)\n else:\n print(\"Item not found.\")\n return my_list\n\n# Example use\nnumbers = [1, 2, 3, 4, 5]\nupdated_list = remove_item(numbers,... |
[
{
"content": "```python\nclass Dog:\n def __init__(self, name):\n self.name = name\n\n def bark(self):\n print(self.name + \" says woof!\")\n```",
"role": "user"
},
{
"content": "This code creates a Dog class that can store a name and make the dog bark.",
"role": "assistant"
... |
[
{
"content": "```python\nimport random\nprint(random.randint(1, 10))\n```",
"role": "user"
},
{
"content": "This code prints a random number between 1 and 10.",
"role": "assistant"
}
] |
[
{
"content": "```python\nimport time\nprint(time.time())\n```",
"role": "user"
},
{
"content": "This code shows the current time in seconds since a starting point called the epoch.",
"role": "assistant"
}
] |
[
{
"content": "```python\nimport sys\\ndef show_args():\\n print(\"Python path:\")\\n for p in sys.path:\\n print(p)\\n print(\"Arguments:\", sys.argv)\\nshow_args()\n```",
"role": "user"
},
{
"content": "This code shows the folders Python searches and prints any command-line argument... |
[
{
"content": "```python\nfruits = [\"apple\", \"banana\", \"cherry\"]\\ndel fruits[1]\\nprint(fruits)\n```",
"role": "user"
},
{
"content": "This code removes the second item from a list and prints the updated list.",
"role": "assistant"
}
] |
[
{
"content": "```python\nclass Dog: __init__=lambda self,n: setattr(self,\"name\",n); __str__=lambda self: self.name\n```",
"role": "user"
},
{
"content": "This code creates a simple class that stores a dog’s name and prints it when turned into a string.",
"role": "assistant"
}
] |
[
{
"content": "```python\nwith open(\"hello.txt\",\"w\") as f: f.write(\"Hi!\")\n```",
"role": "user"
},
{
"content": "This code opens a file safely and writes text to it. Python closes the file automatically.",
"role": "assistant"
}
] |
[
{
"content": "```python\ndef count_letters(words):\\n total = 0\\n for word in words:\\n print(\"Word:\", word)\\n for letter in word:\\n print(\" \", letter)\\n total += 1\\n print(\"Total letters:\", total)\\n return total\\nwords_list = [\"cat\", \"dog\", \"bir... |
[
{
"content": "```python\nimport time\n\ndef show_time_passage():\n print(\"Starting...\")\n time.sleep(1)\n print(\"1 second passed\")\n time.sleep(1)\n print(\"2 seconds passed\")\n current = time.time()\n print(\"Current timestamp:\", current)\n\nshow_time_passage()\n```",
"role": "us... |
[
{
"content": "```python\ndef convert_to_int_list(values):\n result = []\n for v in values:\n try:\n num = int(v)\n result.append(num)\n except ValueError:\n result.append(None)\n print(\"Converted list:\", result)\n total = 0\n for item in result:\n ... |
[
{
"content": "```python\nprint(\"hello world\".find(\"world\"))\nprint(\",\".join([\"a\",\"b\",\"c\"]))\nprint(\"good day\".replace(\"good\",\"great\"))\nprint(\"a b c\".split())\nprint(\"Hello\".swapcase())\n```",
"role": "user"
},
{
"content": "This code shows common string tools like finding word... |
[
{
"content": "```python\nstudent = {\"name\": \"Alex\", \"age\": 12}\nprint(student[\"name\"])\n```",
"role": "user"
},
{
"content": "This code stores information in a dictionary and prints one value.",
"role": "assistant"
}
] |
[
{
"content": "```python\ndef check_conditions(a, b):\n if a > 0 and not b:\n print(\"a is positive and b is False\")\n elif a <= 0 or b:\n print(\"Either a is not positive or b is True\")\n else:\n print(\"No condition met\")\n\ncheck_conditions(5, False)\ncheck_conditions(-1, True... |
[
{
"content": "```python\nclass A:\n def __private_method(self):\n print(\"hidden\")\na = A(); a._A__private_method()\n```",
"role": "user"
},
{
"content": "This code shows how double underscores make a method private, and how it can still be accessed using its mangled name.",
"role": "... |
[
{
"content": "```python\nx=0\nwhile x<3:\n x+=1\n```",
"role": "user"
},
{
"content": "This code uses a while loop to repeat actions as long as a condition is true.",
"role": "assistant"
}
] |
[
{
"content": "```python\ndef format_strings(text):\n lower=text.lower()\n upper=text.upper()\n title=text.title()\n cap=text.capitalize()\n return lower+\"\\n\"+upper+\"\\n\"+title+\"\\n\"+cap\n```",
"role": "user"
},
{
"content": "This function shows how different string methods chan... |
[
{
"content": "```python\ns=\"hello world\"\nresult=s.find(\"o\"),\"-\".join(s.split()),s.replace(\"world\",\"there\"),s.swapcase()\n```",
"role": "user"
},
{
"content": "This code uses string methods to search, join, replace, split, and flip uppercase/lowercase letters.",
"role": "assistant"
}... |
[
{
"content": "```python\ntry:\n a=int(\"abc\")\nexcept ValueError:\n print(\"Not a number\")\ntry:\n 5+\"hi\"\nexcept TypeError:\n print(\"Wrong types\")\n```",
"role": "user"
},
{
"content": "This code shows how Python catches mistakes like using the wrong type of data or trying to conv... |
[
{
"content": "```python\nimport sys\nprint(sys.version)\nprint(len(sys.argv))\nprint(sys.platform)\n```",
"role": "user"
},
{
"content": "This code shows information about Python, like its version, the number of command‑line arguments, and the computer platform.",
"role": "assistant"
}
] |
[
{
"content": "```python\ndef make_variables():\n a = 5\n b = 'hello'\n c = a * 2\n d = b + '!'\n e = c + len(d)\n return a, b, c, d, e\nprint(make_variables())\n```",
"role": "user"
},
{
"content": "This code creates several variables, changes them, and returns them to show how val... |
[
{
"content": "```python\nprint(5 != 3, 7 > 2, 4 <= 4)\n```",
"role": "user"
},
{
"content": "This code compares numbers to check if they are equal or bigger/smaller and prints True or False.",
"role": "assistant"
}
] |
[
{
"content": "```python\nnums = [10, 20, 30, 40]\nprint(nums.index(30))\nnums.pop(1)\nnums.insert(1, 25)\nprint(nums)\n```",
"role": "user"
},
{
"content": "This code finds a value’s position, removes a value, adds a new one, and shows how lists can change.",
"role": "assistant"
}
] |
[
{
"content": "```python\nprint(list(map(lambda x: x * 2, [1, 2, 3])))\n```",
"role": "user"
},
{
"content": "This code uses map to double each number in a list.",
"role": "assistant"
}
] |
[
{
"content": "```python\nimport math\nprint(math.sqrt(16))\n```",
"role": "user"
},
{
"content": "This code imports the math module and uses it to find the square root of 16.",
"role": "assistant"
}
] |
[
{
"content": "```python\ndef remove_item(lst, item):\\n if item in lst:\\n lst.remove(item)\\n print(\"Item removed.\")\\n else:\\n print(\"Item not found.\")\\n print(\"Current list:\")\\n for i in lst:\\n print(i)\\n return lst\\n\nmy_list = [1, 2, 3, 4, 5]\\nremove_... |
[
{
"content": "```python\nclass Animal:\\n def __init__(self, name, sound):\\n self.name = name\\n self.sound = sound\\n def speak(self):\\n return f\"{self.name} says {self.sound}\"\\n def describe(self):\\n return f\"This is a {self.name}.\"\\n\npet = Animal(\"Dog\", \"Woof... |
[
{
"content": "```python\ndef dict_info(d):\\n print(d.items())\\n print(d.keys())\\n print(d.values())\\n d.update({\"z\": 30})\\n print(d)\\n d.pop(\"x\", None)\\n print(d)\\n\nmy_dict = {\"x\": 10, \"y\": 20}\\ndict_info(my_dict)\n```",
"role": "user"
},
{
"content": "This cod... |
[
{
"content": "```python\ndef divide(a, b):\\n if b == 0:\\n raise ValueError(\"Cannot divide by zero!\")\\n return a / b\\n\nprint(divide(10, 2))\\n# print(divide(10, 0))\n```",
"role": "user"
},
{
"content": "This function raises an exception if someone tries to divide by zero.",
"... |
[
{
"content": "```python\nfruits = ['apple', 'banana']\nprint('apple' in fruits)\n```",
"role": "user"
},
{
"content": "This code checks if 'apple' is in the list and prints True.",
"role": "assistant"
}
] |
[
{
"content": "```python\nclass Pet:\n def __init__(self, name):\n self.name = name\n\n def speak(self):\n return f\"My name is {self.name}!\"\n\np = Pet('Buddy')\nprint(p.speak())\n```",
"role": "user"
},
{
"content": "This code creates a class for a pet and lets it say its name.... |
[
{
"content": "```python\ndef count_letters(text):\n counts = {}\n for char in text:\n if char.isalpha():\n if char not in counts:\n counts[char] = 0\n counts[char] += 1\n return counts\n\nprint(count_letters('hello world'))\n```",
"role": "user"
},
{
... |
[
{
"content": "```python\ndef middle_slice(items):\n half = len(items) // 2\n return items[half - 1: half + 2]\n\nnums = [1,2,3,4,5,6]\nprint(middle_slice(nums))\n```",
"role": "user"
},
{
"content": "This code slices a list to get three items from the middle.",
"role": "assistant"
}
] |
[
{
"content": "```python\nx = '42'\ny = int(x)\nz = int(3.99)\nprint(y, z)\n```",
"role": "user"
},
{
"content": "This code changes strings and decimals into whole numbers using int().",
"role": "assistant"
}
] |
[
{
"content": "```python\nclass Test:\\n def __secret(self): print(\"hidden\")\n```",
"role": "user"
},
{
"content": "This code shows a method with two underscores, which makes it harder to access from outside the class.",
"role": "assistant"
}
] |
[
{
"content": "```python\nnums = [1,2,3,4,5]\\nprint(nums[1:4])\n```",
"role": "user"
},
{
"content": "This code slices a list to show only part of it.",
"role": "assistant"
}
] |
[
{
"content": "```python\nimport random\\ndef guess_game():\\n number = random.randint(1, 10)\\n tries = 0\\n while True:\\n guess = random.randint(1, 10)\\n tries += 1\\n if guess == number:\\n print(\"Correct!\", number)\\n break\\n else:\\n ... |
[
{
"content": "```python\ncount = 0\\nwhile count < 3:\\n print(count)\\n count += 1\n```",
"role": "user"
},
{
"content": "This code repeats actions while a condition is true, counting up until it reaches the limit.",
"role": "assistant"
}
] |
[
{
"content": "```python\nx = 5 # this stores a number\\nprint(x)\n```",
"role": "user"
},
{
"content": "This code shows how to write comments using the # symbol.",
"role": "assistant"
}
] |
[
{
"content": "```python\nclass Animal:\n def __init__(self, name, age):\n self.name = name\n self.age = age\n def speak(self):\n return \"Some sound\"\nclass Dog(Animal):\n def __init__(self, name, age, breed):\n super().__init__(name, age)\n self.breed = breed\n d... |
[
{
"content": "```python\na = 5\nb = \"hello\"\n```",
"role": "user"
},
{
"content": "This code makes two variables: one number and one word.",
"role": "assistant"
}
] |
[
{
"content": "```python\ndef ask_user():\n name = input(\"What is your name? \")\n age = input(\"How old are you? \")\n color = input(\"Favorite color? \")\n print(\"Hello\", name)\n print(\"You are\", age, \"years old\")\n print(\"You like\", color)\n summary = f\"{name}, {age}, {color}\"\... |
[
{
"content": "```python\ndef show_tuple():\n t = (1, 2, 3, 4)\n print(t)\n print(t[0])\n print(len(t))\n for item in t:\n print(item)\nshow_tuple()\n```",
"role": "user"
},
{
"content": "This code shows how a tuple works, including reading items and looping through them.",
... |
[
{
"content": "```python\ns = \"Hello World\"\nprint(s)\nprint(s.lower())\nprint(s.upper())\nprint(len(s))\n```",
"role": "user"
},
{
"content": "This code prints a string in different forms and shows its length.",
"role": "assistant"
}
] |
[
{
"content": "```python\n# This function shows how to use comments\n# Comments explain what the code does\n\ndef count_positive(numbers):\n # Start a counter\n count = 0\n # Loop through numbers\n for n in numbers:\n # Check if number is positive\n if n > 0:\n count += 1\n ... |
[
{
"content": "```python\ndef check_number(n):\n if n > 10:\n return \"Big\"\n elif n == 10:\n return \"Exactly 10\"\n elif n > 0:\n return \"Small but positive\"\n else:\n return \"Not positive\"\n\nprint(check_number(7))\n```",
"role": "user"
},
{
"content": ... |
[
{
"content": "```python\nnums = [1, 2, 3]\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\ndef describe_student(student):\n name = student.get(\"name\", \"Unknown\")\n age = student.get(\"age\", 0)\n grade = student.get(\"grade\", \"N/A\")\n\n message = \"Student {n} is {a} years old and in grade {g}.\".format(n=name, a=age, g=grade)\n\n extra = student.get(\"h... |
[
{
"content": "```python\ndef update_scores(scores):\n print(scores.keys())\n print(scores.values())\n print(scores.items())\n scores.update({\"Liam\": 95})\n removed = scores.pop(\"Ava\", 0)\n return scores, removed\n\nprint(update_scores({\"Ava\": 88, \"Noah\": 92}))\n```",
"role": "user"... |
[
{
"content": "```python\n\ndef check_grade(score):\n if score >= 90:\n result = \"A\"\n elif score >= 80:\n result = \"B\"\n elif score >= 70:\n result = \"C\"\n elif score >= 60:\n result = \"D\"\n else:\n result = \"F\"\n print(\"Your grade is:\", result)\n... |
[
{
"content": "```python\nx = int(\"42\")\nprint(x)\n```",
"role": "user"
},
{
"content": "This code changes a number stored as a string into an actual integer.",
"role": "assistant"
}
] |
[
{
"content": "```python\nimport math\nprint(math.sqrt(16))\n```",
"role": "user"
},
{
"content": "This code imports the math module so the program can use math functions like square root.",
"role": "assistant"
}
] |
[
{
"content": "```python\nage = 13\nif age < 10:\n print(\"Child\")\nelif age < 18:\n print(\"Teen\")\nelif age < 65:\n print(\"Adult\")\n```",
"role": "user"
},
{
"content": "This code uses elif to check which age group someone belongs to and prints the correct group.",
"role": "assista... |
[
{
"content": "```python\nadd = lambda a, b: a + b\nprint(add(3, 4))\nprint(add(10, 5))\n```",
"role": "user"
},
{
"content": "This code uses a lambda to make a tiny function that quickly adds two numbers.",
"role": "assistant"
}
] |
[
{
"content": "```python\ntry:\n result = '5' + 3\nexcept TypeError:\n print(\"You tried to mix a string and a number!\")\n\ntry:\n num = int('hello')\nexcept ValueError:\n print(\"This text can't be turned into a number!\")\n```",
"role": "user"
},
{
"content": "This code shows what happ... |
[
{
"content": "```python\nprint(5 > 3 or 2 > 10)\nprint(not False)\n```",
"role": "user"
},
{
"content": "This code shows how Python uses OR to check if at least one thing is true, and NOT to flip true/false values.",
"role": "assistant"
}
] |
[
{
"content": "```python\ntext = \"hELLo wORld\"\nprint(text.lower())\nprint(text.upper())\nprint(text.title())\nprint(text.capitalize())\n```",
"role": "user"
},
{
"content": "This code changes the same text into all‑lowercase, all‑uppercase, title case, and capitalized form.",
"role": "assistan... |
[
{
"content": "```python\nfruit = {\"apple\": 3, \"banana\": 5}\nprint(fruit[\"banana\"])\n```",
"role": "user"
},
{
"content": "This code creates a dictionary and prints the number linked to the key 'banana'.",
"role": "assistant"
}
] |
[
{
"content": "```python\ndef make_paragraph(lines):\n paragraph = \"\"\n for line in lines:\n paragraph += line + \"\\n\"\n return paragraph\n\nstory_lines = [\n \"Once upon a time, there was a cat.\",\n \"It loved to climb trees.\",\n \"One day, it climbed the tallest tree ever!\"\n]\n... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.