{"id":25612,"date":"2024-10-02T14:22:28","date_gmt":"2024-10-02T14:22:28","guid":{"rendered":"https:\/\/machinelearningplus.com\/?p=25612"},"modified":"2025-06-15T03:55:33","modified_gmt":"2025-06-15T03:55:33","slug":"python-exercises-beginner","status":"publish","type":"post","link":"https:\/\/machinelearningplus.com\/python\/python-exercises-beginner\/","title":{"rendered":"Python Exercises &#8211; Level 1"},"content":{"rendered":"<p>This notebook contains Python exercises to practice as a beginner. These are devised as byte sized mini tasks that you might need to apply when programming with Python. By doing these, you gain more experience and tuned to applying Python for more practical situations.<\/p>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2024\/10\/tsuyoshi-kozu-rRuicszmCv0.jpg\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2024\/10\/tsuyoshi-kozu-rRuicszmCv0-1024x683.jpg\" alt=\"\" width=\"1024\" height=\"683\" class=\"aligncenter size-large wp-image-25631\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2024\/10\/tsuyoshi-kozu-rRuicszmCv0-1024x683.jpg 1024w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2024\/10\/tsuyoshi-kozu-rRuicszmCv0-300x200.jpg 300w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2024\/10\/tsuyoshi-kozu-rRuicszmCv0-768x512.jpg 768w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2024\/10\/tsuyoshi-kozu-rRuicszmCv0.jpg 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p><strong>Who is this for?<\/strong><\/p>\n<p>You already know Python basics and want to get practice or prepare for coding interviews, this will a good set to practice. You understand the python syntax and data types (integers, strings, lists, dictionaries, etc.) and you are able to write simple Python programs such as functions and use the standard library<\/p>\n<p>Experience Level:<br \/>\nYou have started learning Python recently or has only worked on small, straightforward projects.<\/p>\n<p><em><strong>Note:<\/strong> If you are looking for exercises on Data Analysis, check out the <strong><a href=\"https:\/\/machinelearningplus.com\/python\/101-pandas-exercises-python\/\" rel=\"noopener\" target=\"_blank\">101 Pandas Exercises<\/a>.<\/em><\/strong><\/p>\n<h2>Q1. Find numbers Divisible by 7, not by 5<\/h2>\n<p>Create a Python program that identifies all numbers between 100 and 300 (inclusive) that are divisible by 7 but not multiples of 5. The identified numbers should be displayed in a single line, separated by commas.<\/p>\n<p><strong>Level:<\/strong> Beginner<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">find_numbers(100, 200)\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">112,119,126,133,147,154,161,168,182,189,196\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Use the range(#start, #stop) function to iterate over the specified range.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">def find_numbers(start, end):\r\n    result = []\r\n    for i in range(start, end + 1):\r\n        if i % 7 == 0 and i % 5 != 0:\r\n            result.append(str(i))\r\n    return ','.join(result)\r\n\r\n# Call the function with specific start and end values\r\nprint(find_numbers(100, 200))\r\n<\/code><\/pre>\n<pre><code>112,119,126,133,147,154,161,168,182,189,196\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q2: Generate Square Dictionary<\/h2>\n<p>Create a Python function that takes an integer ( n ) as input and generates a dictionary containing pairs ( (i, i^2) ) for all integers ( i ) from 1 to ( n ) (inclusive). The function should then return this dictionary.<\/p>\n<p><strong>Level:<\/strong> Beginner<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">generate_square_dict(8)\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<ul>\n<li>Use the <code>dict()<\/code> function to create an empty dictionary.<\/li>\n<li>Iterate through the range from 1 to ( n ) using a loop.<\/li>\n<\/ul>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">\r\ndef generate_square_dict(n):\r\n    d = dict()\r\n    for i in range(1, n + 1):\r\n        d[i] = i * i\r\n    return d\r\n\r\ngenerate_square_dict(8)\r\n\r\n<\/code><\/pre>\n<pre><code>{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q3. Sequence to List and Tuple<\/h2>\n<p>Create a Python function that takes a sequence of comma-separated numbers as input and generates both a list and a tuple containing those numbers.<\/p>\n<p><strong>Level:<\/strong> Beginner<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">convert_input_to_list_and_tuple(&quot;3,6,5,3,2,8&quot;)\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">(['3', '6', '5', '3', '2', '8'], ('3', '6', '5', '3', '2', '8'))\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<ul>\n<li>The input will be provided as a string.<\/li>\n<li>Use the <code>split(&quot;,&quot;)<\/code> method to convert the string into a list.<\/li>\n<li>The <code>tuple()<\/code> method can convert a list into a tuple.<\/li>\n<\/ul>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<p>Here is the Solution:<\/p>\n<pre><code class=\"language-python\">\r\ndef convert_input_to_list_and_tuple(input_string):\r\n    values = input_string.split(&quot;,&quot;)\r\n    return values, tuple(values)\r\n\r\nconvert_input_to_list_and_tuple(&quot;3,6,5,3,2,8&quot;)\r\n\r\n<\/code><\/pre>\n<pre><code>(['3', '6', '5', '3', '2', '8'], ('3', '6', '5', '3', '2', '8'))\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q4. String Manipulation Class<\/h2>\n<p>Define a class that contains at least two methods: <code>get_string<\/code> to retrieve a string from console input and <code>print_string<\/code> to display the string in uppercase. Additionally, include a simple test function to validate the class methods.<\/p>\n<p><strong>Difficulty:<\/strong> Level 1<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">str_obj = InputOutString()\nstr_obj.get_string()\nstr_obj.print_string()\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<p>If the input string is &quot;hello world&quot;, the output will be:<\/p>\n<pre><code>HELLO WORLD\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Utilize the <code>__init__<\/code> method to initialize the class parameters.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">class InputOutString:\r\n    def __init__(self):\r\n        self.s = &quot;&quot;\r\n\r\n    def get_string(self):\r\n        self.s = input(&quot;Enter a string: &quot;)\r\n\r\n    def print_string(self):\r\n        print(self.s.upper())\r\n\r\n# Test function\r\n\r\nstr_obj = InputOutString()\r\nstr_obj.get_string()\r\nstr_obj.print_string()\r\n\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q5. Calculate Q Values from D<\/h2>\n<p>Create a Python function that computes the value of ( Q ) using the formula:<\/p>\n<p>$$<br \/>\nQ = \\sqrt{\\frac{(2 \\cdot C \\cdot D)}{H}}<br \/>\n$$<\/p>\n<p>where ( C ) is 50 and ( H ) is 30. The function should take only ( D ) as input, which consists of a comma-separated sequence of values. The output should be rounded to the nearest integer and printed in a single line, separated by commas.<\/p>\n<p><strong>Difficulty:<\/strong> Level 1<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">calculate_q_values(&quot;100,150,180&quot;)  # 100,150,180 are possible values of D\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">18,22,24\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<ul>\n<li>Use the <code>math.sqrt()<\/code> function to compute the square root.<\/li>\n<li>Convert input values to float for calculation, and round the result using the <code>round()<\/code> function.<\/li>\n<\/ul>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">import math\r\n\r\ndef calculate_q_values(d_values):\r\n    C = 50\r\n    H = 30\r\n    value = []\r\n    items = [float(x) for x in d_values.split(',')]\r\n    for D in items:\r\n        Q = round(math.sqrt((2 * C * D) \/ H))\r\n        value.append(str(Q))\r\n    return ','.join(value)\r\n\r\ncalculate_q_values('5,50,500')\r\n<\/code><\/pre>\n<pre><code>'4,13,41'\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q6:  Table Matrix<\/h2>\n<p>Create a Python program that takes two digits, <code>M<\/code> and <code>N<\/code>, as inputs and generates a two-dimensional array. The value at the i-th row and j-th column of the array should be <code>i*j<\/code>.<\/p>\n<p><strong>Difficulty:<\/strong> Level 2<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">create_matrix(4, 3)\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">[[0, 0, 0], \n [0, 1, 2], \n [0, 2, 4], \n [0, 3, 6]]\n\n# Ex: 6 belongs to row=3, column=2 \n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Use a nested list comprehension to construct the 2D matrix.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">\r\ndef create_matrix(M, N):\r\n    return [[i * j for j in range(N)] for i in range(M)]\r\n\r\ncreate_matrix(4,3)\r\n\r\n<\/code><\/pre>\n<pre><code>[[0, 0, 0], [0, 1, 2], [0, 2, 4], [0, 3, 6]]\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q7. Sort Comma-Separated Words<\/h2>\n<p>Create a Python program that accepts a sequence of comma-separated words as input and returns the words sorted in alphabetical order.<\/p>\n<p><strong>Difficulty:<\/strong> Level 2<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">sort_words('banana,apple,grape,orange')\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">'apple,banana,grape,orange'\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Use the <code>split(',')<\/code> method to break the input into a list of words and <code>sorted()<\/code> to sort the list.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">def sort_words(words):\r\n    return ','.join(sorted(words.split(',')))\r\n\r\nsort_words('banana,apple,grape,orange')\r\n<\/code><\/pre>\n<pre><code>'apple,banana,grape,orange'\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q8. Capitalize All Lines<\/h2>\n<p>Create a Python program that takes a sequence of lines as input and returns each line capitalized.<\/p>\n<p><strong>Difficulty:<\/strong> Level 2<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">capitalize_lines(['Sundays are Fun', 'Monday is Done'])\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">[['SUNDAYS ARE FUN', 'MONDAY IS DONE']]\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Use a list comprehension and the <code>.upper()<\/code> method to capitalize each line.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">\r\ndef capitalize_lines(lines):\r\n    return [line.upper() for line in lines]\r\n\r\ncapitalize_lines(['Sundays are Fun', 'Monday is Done'])\r\n<\/code><\/pre>\n<pre><code>['SUNDAYS ARE FUN', 'MONDAY IS DONE']\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q9. Unique Sorted Words<\/h2>\n<p>Create a Python program that accepts a sequence of whitespace-separated words as input and returns them sorted alphabetically with duplicates removed.<\/p>\n<p><strong>Difficulty:<\/strong> Level 2<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">unique_sorted_words('dog cat apple cat banana dog')\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">'apple banana cat dog'\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Use a <code>set<\/code> to remove duplicates and <code>sorted()<\/code> to sort the words.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">\r\ndef unique_sorted_words(sentence):\r\n    return ' '.join(sorted(set(sentence.split())))\r\n\r\nunique_sorted_words('dog cat apple cat banana dog')    \r\n\r\n<\/code><\/pre>\n<pre><code>'apple banana cat dog'\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q10. Binary Divisible by 5<\/h2>\n<p>Create a Python program that accepts a sequence of comma-separated 4-digit binary numbers as input and checks if they are divisible by 5. The valid numbers should be returned in a comma-separated sequence.<\/p>\n<p><strong>Difficulty:<\/strong> Level 2<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">binary_divisible_by_5('1101,1010,1111,1001')\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">'1010'\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Convert each binary number to decimal using <code>int()<\/code> and check divisibility by 5.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<p>def binary_divisible_by_5(binaries):<br \/>\nreturn &#8216;,&#8217;.join([b for b in binaries.split(&#8216;,&#8217;) if int(b, 2) % 5 == 0])<\/p>\n<p>binaries = &#8216;1101,1010,1111,1001&#8217;<br \/>\nbinary_divisible_by_5(binaries)<\/p>\n<p><\/div><\/details>\n<h2>Q11. All Even Digits<\/h2>\n<p>Create a Python program that finds all numbers between 1200 and 2100 (both inclusive) where each digit is an even number. The numbers should be returned as a comma-separated sequence.<\/p>\n<p><strong>Difficulty:<\/strong> Level 2<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">even_digit_numbers(1200, 2010)\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">'2000,2002,2004,2006,2008'\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Check if all digits of a number are even using modulo operator <code>%<\/code>.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">def even_digit_numbers(start, end):\r\n    return ','.join([str(num) for num in range(start, end + 1) if all(int(digit) % 2 == 0 for digit in str(num))])\r\n\r\neven_digit_numbers(1200, 2010)\r\n<\/code><\/pre>\n<pre><code>'2000,2002,2004,2006,2008'\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q12. Count Letters and Digits<\/h2>\n<p>Create a Python program that accepts a sentence and calculates the number of letters and digits.<\/p>\n<p><strong>Difficulty:<\/strong> Level 2<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">count_letters_digits('Data123 Science 2024')\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">{'LETTERS': 11, 'DIGITS': 7}\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Use <code>isalpha()<\/code> to check for letters and <code>isdigit()<\/code> to check for digits.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">\r\ndef count_letters_digits(sentence):\r\n    counts = {&quot;LETTERS&quot;: 0, &quot;DIGITS&quot;: 0}\r\n    for char in sentence:\r\n        if char.isalpha():\r\n            counts[&quot;LETTERS&quot;] += 1\r\n        elif char.isdigit():\r\n            counts[&quot;DIGITS&quot;] += 1\r\n    return counts\r\n\r\ncount_letters_digits('Data123 Science 2024')\r\n\r\n<\/code><\/pre>\n<pre><code>{'LETTERS': 11, 'DIGITS': 7}\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q13. Count Upper and Lower Case<\/h2>\n<p>Create a Python program that accepts a sentence and calculates the number of uppercase and lowercase letters.<\/p>\n<p><strong>Difficulty:<\/strong> Level 2<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">count_case('Hello World!')\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">{'UPPER CASE': 2, 'LOWER CASE': 8}\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Use <code>isupper()<\/code> and <code>islower()<\/code> methods to distinguish between upper and lower case letters.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">\r\ndef count_case(sentence):\r\n    counts = {&quot;UPPER CASE&quot;: 0, &quot;LOWER CASE&quot;: 0}\r\n    for char in sentence:\r\n        if char.isupper():\r\n            counts[&quot;UPPER CASE&quot;] += 1\r\n        elif char.islower():\r\n            counts[&quot;LOWER CASE&quot;] += 1\r\n    return counts\r\n    \r\ncount_case('Hello World!')\r\n\r\n<\/code><\/pre>\n<pre><code>{'UPPER CASE': 2, 'LOWER CASE': 8}\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q14. Sum of a + aa + aaa + aaaa<\/h2>\n<p>Create a Python program that calculates the value of a + aa + aaa + aaaa for a given digit <code>a<\/code>.<\/p>\n<p><strong>Difficulty:<\/strong> Level 2<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">sum_of_series(7)\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">8638\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Use string multiplication and <code>int()<\/code> to construct each term of the series.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">def sum_of_series(a):\r\n    return sum(int(str(a) * i) for i in range(1, 5))\r\n\r\n\r\nsum_of_series(7)\r\n\r\n<\/code><\/pre>\n<pre><code>8638\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q15. Circle Class<\/h2>\n<p>Create a Python class <code>Circle<\/code> that accepts a radius as a parameter and has a method to compute the area of the circle.<\/p>\n<p><strong>Difficulty:<\/strong> Level 1<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">aCircle = Circle(3)\nprint(aCircle.area())\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">28.26  # pi*r*r\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Use the formula <code>\u03c0r\u00b2<\/code> to calculate the area of the circle.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">class Circle:\r\n    def __init__(self, radius):\r\n        self.radius = radius\r\n\r\n    def area(self):\r\n        return self.radius ** 2 * 3.14\r\n\r\n# Example usage\r\naCircle = Circle(3)\r\nprint(aCircle.area())\r\n\r\n<\/code><\/pre>\n<pre><code>28.26\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q16. Shape and Square Area<\/h2>\n<p>Create a Python class <code>Shape<\/code> and a subclass <code>Square<\/code>. The <code>Square<\/code> class takes a length as a parameter and both classes have a method to compute the area. The area of <code>Shape<\/code> is 0 by default, while the area of <code>Square<\/code> is the square of its side length.<\/p>\n<p><strong>Difficulty:<\/strong> Level 2<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">aSquare = Square(4)\nprint(aSquare.area())\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">16\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Override the <code>area<\/code> method in the <code>Square<\/code> class.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">class Shape:\r\n    def area(self):\r\n        return 0\r\n\r\nclass Square(Shape):\r\n    def __init__(self, length):\r\n        self.length = length\r\n\r\n    def area(self):\r\n        return self.length ** 2\r\n\r\n# Example usage\r\naSquare = Square(4)\r\nprint(aSquare.area())\r\n\r\n<\/code><\/pre>\n<pre><code>16\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q17. Handle Division by Zero<\/h2>\n<p>Write a Python function that attempts to compute <code>10 \/ 0<\/code> and catches the exception.<\/p>\n<p><strong>Difficulty:<\/strong> Level 1<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">catch_zero_division()\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">&quot;division by zero!&quot;\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Use try\/except to handle the exception.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\">\n<pre><code class=\"language-python\">\r\ndef catch_zero_division():\r\n    try:\r\n        return 10 \/ 0\r\n    except ZeroDivisionError:\r\n        print(&quot;division by zero!&quot;)\r\n\r\n# Example usage\r\ncatch_zero_division()\r\n\r\n\r\n\r\n<\/code><\/pre>\n<pre><code>division by zero!\r\n<\/code><\/pre>\n<pre><code class=\"language-python\">\r\n<\/div><\/details>\n\n<h2>Q19. Extract Username from Email<\/h2>\n\nCreate a Python program that extracts and prints the username from a given email address in the format <code>username@company.com<\/code>.\n\n<strong>Difficulty:<\/strong> Level 2\n\n<strong>Input:<\/strong>\n\n```python\nextract_username(&quot;alice@company.com&quot;)\n&lt;\/code&gt;&lt;\/pre&gt;\n\n&lt;strong&gt;Expected Output:&lt;\/strong&gt;\n\n&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;&quot;alice&quot;\n&lt;\/code&gt;&lt;\/pre&gt;\n\n&lt;strong&gt;Hints:&lt;\/strong&gt;\n\nUse regular expressions to extract the username.\n\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">&#039;Show<\/summary><div class=\"blogv4-expand__body\">\r\n&lt;pre&gt;&lt;code&gt;\r\n\r\n```python\r\n\r\n\r\nimport re\r\n\r\ndef extract_username(email):\r\n    match = re.match(r&quot;(\\w+)@(\\w+\\.\\w+)&quot;, email)\r\n    return match.group(1)\r\n\r\n# Example usage\r\nprint(extract_username(&quot;alice@company.com&quot;))\r\n\r\n\r\n<\/code><\/pre>\n<p><\/div><\/details><\/p>\n<h2>Q18. Recursive Function for f(n)<\/h2>\n<p>Create a Python function <code>f(n)<\/code> such that <code>f(n) = f(n-1) + 100<\/code> when <code>n &gt; 0<\/code> and <code>f(0) = 1<\/code>.<\/p>\n<p><strong>Difficulty:<\/strong> Level 2<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">print(f(5))\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">501\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Use a recursive function to compute the value of <code>f(n)<\/code>.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">def f(n):\r\n    if n == 0:\r\n        return 1\r\n    else:\r\n        return f(n - 1) + 100\r\n\r\n# Example usage\r\nprint(f(5))\r\n<\/code><\/pre>\n<pre><code>501\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q19. Generate Random Numbers<\/h2>\n<p>Write a Python function that generates a list of 5 random numbers between 150 and 250 (inclusive).<\/p>\n<p><strong>Difficulty:<\/strong> Level 1<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">print(generate_random_numbers())\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">[160, 183, 194, 203, 224]\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Use <code>random.sample()<\/code> to generate random values from a specified range.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">\r\nimport random\r\n\r\ndef generate_random_numbers():\r\n    return random.sample(range(150, 251), 5)\r\n\r\n# Example usage\r\nprint(generate_random_numbers())\r\n\r\n\r\n<\/code><\/pre>\n<pre><code>[189, 160, 192, 155, 168]\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q20. Generate Even Numbers<\/h2>\n<p>Write a Python function that generates a list of 5 even numbers randomly between 150 and 250 (inclusive).<\/p>\n<p><strong>Difficulty:<\/strong> Level 1<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">print(generate_even_numbers())\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">[160, 182, 200, 224, 246]\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Use <code>random.sample()<\/code> to pick random even numbers from a list.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">\r\nimport random\r\n\r\ndef generate_even_numbers():\r\n    return random.sample([i for i in range(150, 251) if i % 2 == 0], 5)\r\n\r\n# Example usage\r\nprint(generate_even_numbers())\r\n\r\n\r\n<\/code><\/pre>\n<pre><code>[192, 168, 176, 170, 242]\r\n<\/code><\/pre>\n<p><\/div><\/details>\n<h2>Q21. Measure Execution Time<\/h2>\n<p>Write a Python program to measure the execution time of the expression <code>2+2<\/code> repeated 10000 times.<\/p>\n<p><strong>Difficulty:<\/strong> Level 1<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code class=\"language-python\">print(measure_execution_time())\n<\/code><\/pre>\n<p><strong>Expected Output:<\/strong><\/p>\n<pre><code class=\"language-python\">Execution Time: 0.00012 seconds\n<\/code><\/pre>\n<p><strong>Hints:<\/strong><\/p>\n<p>Use <code>time.time()<\/code> to measure the time.<\/p>\n<details class=\"blogv4-expand\"><summary class=\"blogv4-expand__toggle\">Show Solution<\/summary><div class=\"blogv4-expand__body\"><\/p>\n<pre><code class=\"language-python\">import time\r\n\r\ndef measure_execution_time():\r\n    start = time.time()\r\n    for _ in range(10000):\r\n        1 + 1\r\n    end = time.time()\r\n    return f&quot;Execution Time: {end - start} seconds&quot;\r\n\r\n# Example usage\r\nprint(measure_execution_time())\r\n\r\n<\/code><\/pre>\n<pre><code>Execution Time: 0.0005338191986083984 seconds\r\n<\/code><\/pre>\n<p><\/div><\/details>\n","protected":false},"excerpt":{"rendered":"<p>This notebook contains Python exercises to practice as a beginner. These are devised as byte sized mini tasks that you might need to apply when programming with Python. By doing these, you gain more experience and tuned to applying Python for more practical situations. Who is this for? You already know Python basics and want [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[21],"tags":[1878,22],"class_list":["post-25612","post","type-post","status-publish","format-standard","hentry","category-python","tag-exercises","tag-python"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Exercises - Level 1 (with solutions For Beginners)<\/title>\n<meta name=\"description\" content=\"Python exercises to practice as a beginner. These are devised as mini tasks that you might need to apply when programming with Python.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/localhost:8080\/python\/python-exercises-beginner\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Exercises - Level 1 (with solutions For Beginners)\" \/>\n<meta property=\"og:description\" content=\"Python exercises to practice as a beginner. These are devised as mini tasks that you might need to apply when programming with Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/localhost:8080\/python\/python-exercises-beginner\/\" \/>\n<meta property=\"og:site_name\" content=\"machinelearningplus\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-02T14:22:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-15T03:55:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2024\/10\/tsuyoshi-kozu-rRuicszmCv0.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"800\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Team Machine Learning Plus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Team Machine Learning Plus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/localhost:8080\\\/python\\\/python-exercises-beginner\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/localhost:8080\\\/python\\\/python-exercises-beginner\\\/\"},\"author\":{\"name\":\"Team Machine Learning Plus\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#\\\/schema\\\/person\\\/1a213d5719b6c3b2fcb79ea3d81e0c30\"},\"headline\":\"Python Exercises &#8211; Level 1\",\"datePublished\":\"2024-10-02T14:22:28+00:00\",\"dateModified\":\"2025-06-15T03:55:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/localhost:8080\\\/python\\\/python-exercises-beginner\\\/\"},\"wordCount\":1259,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/localhost:8080\\\/python\\\/python-exercises-beginner\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/tsuyoshi-kozu-rRuicszmCv0-1024x683.jpg\",\"keywords\":[\"Exercises\",\"Python\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/localhost:8080\\\/python\\\/python-exercises-beginner\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/localhost:8080\\\/python\\\/python-exercises-beginner\\\/\",\"url\":\"https:\\\/\\\/localhost:8080\\\/python\\\/python-exercises-beginner\\\/\",\"name\":\"Python Exercises - Level 1 (with solutions For Beginners)\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/localhost:8080\\\/python\\\/python-exercises-beginner\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/localhost:8080\\\/python\\\/python-exercises-beginner\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/tsuyoshi-kozu-rRuicszmCv0-1024x683.jpg\",\"datePublished\":\"2024-10-02T14:22:28+00:00\",\"dateModified\":\"2025-06-15T03:55:33+00:00\",\"description\":\"Python exercises to practice as a beginner. These are devised as mini tasks that you might need to apply when programming with Python.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/localhost:8080\\\/python\\\/python-exercises-beginner\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/localhost:8080\\\/python\\\/python-exercises-beginner\\\/#primaryimage\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/tsuyoshi-kozu-rRuicszmCv0.jpg\",\"contentUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/tsuyoshi-kozu-rRuicszmCv0.jpg\",\"width\":1200,\"height\":800},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#website\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/\",\"name\":\"machinelearningplus\",\"description\":\"Learn Data Science (AI \\\/ ML) Online\",\"publisher\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/machinelearningplus.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#organization\",\"name\":\"machinelearningplus\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/MachineLearningplus-logo.svg\",\"contentUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/MachineLearningplus-logo.svg\",\"width\":348,\"height\":36,\"caption\":\"machinelearningplus\"},\"image\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#\\\/schema\\\/person\\\/1a213d5719b6c3b2fcb79ea3d81e0c30\",\"name\":\"Team Machine Learning Plus\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/litespeed\\\/avatar\\\/4e3baab7450669bdbbc4b287a6f46e39.jpg?ver=1783630503\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/litespeed\\\/avatar\\\/4e3baab7450669bdbbc4b287a6f46e39.jpg?ver=1783630503\",\"contentUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/litespeed\\\/avatar\\\/4e3baab7450669bdbbc4b287a6f46e39.jpg?ver=1783630503\",\"caption\":\"Team Machine Learning Plus\"},\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/author\\\/rivan\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Exercises - Level 1 (with solutions For Beginners)","description":"Python exercises to practice as a beginner. These are devised as mini tasks that you might need to apply when programming with Python.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/localhost:8080\/python\/python-exercises-beginner\/","og_locale":"en_US","og_type":"article","og_title":"Python Exercises - Level 1 (with solutions For Beginners)","og_description":"Python exercises to practice as a beginner. These are devised as mini tasks that you might need to apply when programming with Python.","og_url":"https:\/\/localhost:8080\/python\/python-exercises-beginner\/","og_site_name":"machinelearningplus","article_published_time":"2024-10-02T14:22:28+00:00","article_modified_time":"2025-06-15T03:55:33+00:00","og_image":[{"width":1200,"height":800,"url":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2024\/10\/tsuyoshi-kozu-rRuicszmCv0.jpg","type":"image\/jpeg"}],"author":"Team Machine Learning Plus","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Team Machine Learning Plus","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/localhost:8080\/python\/python-exercises-beginner\/#article","isPartOf":{"@id":"https:\/\/localhost:8080\/python\/python-exercises-beginner\/"},"author":{"name":"Team Machine Learning Plus","@id":"https:\/\/machinelearningplus.com\/#\/schema\/person\/1a213d5719b6c3b2fcb79ea3d81e0c30"},"headline":"Python Exercises &#8211; Level 1","datePublished":"2024-10-02T14:22:28+00:00","dateModified":"2025-06-15T03:55:33+00:00","mainEntityOfPage":{"@id":"https:\/\/localhost:8080\/python\/python-exercises-beginner\/"},"wordCount":1259,"commentCount":0,"publisher":{"@id":"https:\/\/machinelearningplus.com\/#organization"},"image":{"@id":"https:\/\/localhost:8080\/python\/python-exercises-beginner\/#primaryimage"},"thumbnailUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2024\/10\/tsuyoshi-kozu-rRuicszmCv0-1024x683.jpg","keywords":["Exercises","Python"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/localhost:8080\/python\/python-exercises-beginner\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/localhost:8080\/python\/python-exercises-beginner\/","url":"https:\/\/localhost:8080\/python\/python-exercises-beginner\/","name":"Python Exercises - Level 1 (with solutions For Beginners)","isPartOf":{"@id":"https:\/\/machinelearningplus.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/localhost:8080\/python\/python-exercises-beginner\/#primaryimage"},"image":{"@id":"https:\/\/localhost:8080\/python\/python-exercises-beginner\/#primaryimage"},"thumbnailUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2024\/10\/tsuyoshi-kozu-rRuicszmCv0-1024x683.jpg","datePublished":"2024-10-02T14:22:28+00:00","dateModified":"2025-06-15T03:55:33+00:00","description":"Python exercises to practice as a beginner. These are devised as mini tasks that you might need to apply when programming with Python.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/localhost:8080\/python\/python-exercises-beginner\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/localhost:8080\/python\/python-exercises-beginner\/#primaryimage","url":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2024\/10\/tsuyoshi-kozu-rRuicszmCv0.jpg","contentUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2024\/10\/tsuyoshi-kozu-rRuicszmCv0.jpg","width":1200,"height":800},{"@type":"WebSite","@id":"https:\/\/machinelearningplus.com\/#website","url":"https:\/\/machinelearningplus.com\/","name":"machinelearningplus","description":"Learn Data Science (AI \/ ML) Online","publisher":{"@id":"https:\/\/machinelearningplus.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/machinelearningplus.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/machinelearningplus.com\/#organization","name":"machinelearningplus","url":"https:\/\/machinelearningplus.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/machinelearningplus.com\/#\/schema\/logo\/image\/","url":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2022\/05\/MachineLearningplus-logo.svg","contentUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2022\/05\/MachineLearningplus-logo.svg","width":348,"height":36,"caption":"machinelearningplus"},"image":{"@id":"https:\/\/machinelearningplus.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/machinelearningplus.com\/#\/schema\/person\/1a213d5719b6c3b2fcb79ea3d81e0c30","name":"Team Machine Learning Plus","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/machinelearningplus.com\/wp-content\/litespeed\/avatar\/4e3baab7450669bdbbc4b287a6f46e39.jpg?ver=1783630503","url":"https:\/\/machinelearningplus.com\/wp-content\/litespeed\/avatar\/4e3baab7450669bdbbc4b287a6f46e39.jpg?ver=1783630503","contentUrl":"https:\/\/machinelearningplus.com\/wp-content\/litespeed\/avatar\/4e3baab7450669bdbbc4b287a6f46e39.jpg?ver=1783630503","caption":"Team Machine Learning Plus"},"url":"https:\/\/machinelearningplus.com\/author\/rivan\/"}]}},"_links":{"self":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/posts\/25612","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/comments?post=25612"}],"version-history":[{"count":0,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/posts\/25612\/revisions"}],"wp:attachment":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/media?parent=25612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/categories?post=25612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/tags?post=25612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}