Skip to content
Snippets Groups Projects
Commit ec1ceb5e authored by David Paul's avatar David Paul
Browse files

Replace tabs with spaces in provided code in exercises

parent 35f66844
No related branches found
No related tags found
No related merge requests found
...@@ -30,7 +30,7 @@ exercises.append(exercise) ...@@ -30,7 +30,7 @@ exercises.append(exercise)
# Exercise 3 # Exercise 3
exercise = Exercise("Right Justify") exercise = Exercise("Right Justify")
exercise.instructions = "Write a function named <em>right_justify</em> that takes a string named <em>input_string</em> as a parameter. If the input string is longer than 79 characters, the string should be printed as is, Otherwise, the function should print the string with enough leading spaces that the last letter of the string is in column 80 of the display. (Note: Python has an inbuilt function called len that returns the length of a string. You can use this function to help perform the task)." exercise.instructions = "Write a function named <em>right_justify</em> that takes a string named <em>input_string</em> as a parameter. If the input string is longer than 79 characters, the string should be printed as is, Otherwise, the function should print the string with enough leading spaces that the last letter of the string is in column 80 of the display. (Note: Python has an inbuilt function called len that returns the length of a string. You can use this function to help perform the task)."
exercise.code = "def right_justify(input_string):\n\tpass # TODO: Complete this function\n\nvalue = input(\"Enter string to justify: \")\nright_justify(value)" exercise.code = "def right_justify(input_string):\n pass # TODO: Complete this function\n\nvalue = input(\"Enter string to justify: \")\nright_justify(value)"
exercise.tests = [Test("Short string", "Enter string to justify: hello\n hello\n", "hello"), exercise.tests = [Test("Short string", "Enter string to justify: hello\n hello\n", "hello"),
Test("Long string", "Enter string to justify: This is a longer string that does not actually need to be justified. It is already long enough.\nThis is a longer string that does not actually need to be justified. It is already long enough.\n", "This is a longer string that does not actually need to be justified. It is already long enough."), Test("Long string", "Enter string to justify: This is a longer string that does not actually need to be justified. It is already long enough.\nThis is a longer string that does not actually need to be justified. It is already long enough.\n", "This is a longer string that does not actually need to be justified. It is already long enough."),
Test("Under limit string", "Enter string to justify: This string is exactly 79 characters long & so does require some justification.\n This string is exactly 79 characters long & so does require some justification.\n", "This string is exactly 79 characters long & so does require some justification."), Test("Under limit string", "Enter string to justify: This string is exactly 79 characters long & so does require some justification.\n This string is exactly 79 characters long & so does require some justification.\n", "This string is exactly 79 characters long & so does require some justification."),
...@@ -73,7 +73,7 @@ exercises.append(exercise) ...@@ -73,7 +73,7 @@ exercises.append(exercise)
# Exercise 6 # Exercise 6
exercise = Exercise("Palindromes") exercise = Exercise("Palindromes")
exercise.instructions = "<p>A <a href=\"https://en.wikipedia.org/wiki/Palindrome\">palindrome</a> is a sequence of characters which reads the same backward or forward. For example, \"anna\" is a palindrome because reversing the letters gives \"anna\", which is the same as when the letters are not reversed.</p><p>Write a recursive function called <em>is_palindrome</em> that takes a string named <em>word</em> as its parameter and returns True if <em>word</em> has length less than or equal to 1. If the length of word is greater than 1, the function should return False if the first character of <em>word</em> is different to the last character of <em>word</em>. If the length of <em>word</em> is greater than 1, and the first and last characters of the string are identical, the function should return the result of <em>is_palindrome()</em> with the parameter of <em>word</em> with its first and last characters removed (e.g. <em>is_palindrome(\"anna\")</em> should return the result of <em>is_palindrome(\"nn\")</em>).</p>" exercise.instructions = "<p>A <a href=\"https://en.wikipedia.org/wiki/Palindrome\">palindrome</a> is a sequence of characters which reads the same backward or forward. For example, \"anna\" is a palindrome because reversing the letters gives \"anna\", which is the same as when the letters are not reversed.</p><p>Write a recursive function called <em>is_palindrome</em> that takes a string named <em>word</em> as its parameter and returns True if <em>word</em> has length less than or equal to 1. If the length of word is greater than 1, the function should return False if the first character of <em>word</em> is different to the last character of <em>word</em>. If the length of <em>word</em> is greater than 1, and the first and last characters of the string are identical, the function should return the result of <em>is_palindrome()</em> with the parameter of <em>word</em> with its first and last characters removed (e.g. <em>is_palindrome(\"anna\")</em> should return the result of <em>is_palindrome(\"nn\")</em>).</p>"
exercise.code = "def is_palindrome(word):\n\tpass # TODO: Implement this function\n\npossible_palindrome = input(\"Enter a word/phrase to check: \")\nif is_palindrome(possible_palindrome):\n\tprint(possible_palindrome, \"is a palindrome\")\nelse:\n\tprint(possible_palindrome, \"is not a palindrome\")" exercise.code = "def is_palindrome(word):\n pass # TODO: Implement this function\n\npossible_palindrome = input(\"Enter a word/phrase to check: \")\nif is_palindrome(possible_palindrome):\n print(possible_palindrome, \"is a palindrome\")\nelse:\n print(possible_palindrome, \"is not a palindrome\")"
exercise.tests = [Test("a", "Enter a word/phrase to check: a\na is a palindrome\n", "a"), exercise.tests = [Test("a", "Enter a word/phrase to check: a\na is a palindrome\n", "a"),
Test("anna", "Enter a word/phrase to check: anna\nanna is a palindrome\n", "anna"), Test("anna", "Enter a word/phrase to check: anna\nanna is a palindrome\n", "anna"),
Test("banana", "Enter a word/phrase to check: banana\nbanana is not a palindrome\n", "banana"), Test("banana", "Enter a word/phrase to check: banana\nbanana is not a palindrome\n", "banana"),
...@@ -114,7 +114,7 @@ exercises.append(exercise) ...@@ -114,7 +114,7 @@ exercises.append(exercise)
# Exercise 10 # Exercise 10
exercise = Exercise("Test-Driven Development") exercise = Exercise("Test-Driven Development")
exercise.instructions = "An online store requires a Python function to calculate the price of orders. The function should be called <code>calculate_price</code> and take the following two arguments (in order):<ul><li><code>price</code>: A dictionary mapping the name of each item sold by the store to the price of the item (in dollars)</li><li><code>order</code>: A dictionary mapping the name of each item a customer wishes to buy to the quantity of that item they wish to purchase</li></ul>The function should iterate over each item in the order and add the price to buy the desired quantity of that item to the total cost of the order. If any item in the order does not have a corresponding price, your function should raise a <code>KeyError</code>.<p>Once the cost of each item in the order has been calculated, the function should test to see if the overall cost for all items is greater than $100. If it is, a 10% discount should be applied to the overall cost. Otherwise, if the order is greater than $50, a 5% discount should be applied.</p><p>The overall cost of the order (after any applicable discounts) should then be returned by the function.</p><p>Write a function to meet these requirements.</p>" exercise.instructions = "An online store requires a Python function to calculate the price of orders. The function should be called <code>calculate_price</code> and take the following two arguments (in order):<ul><li><code>price</code>: A dictionary mapping the name of each item sold by the store to the price of the item (in dollars)</li><li><code>order</code>: A dictionary mapping the name of each item a customer wishes to buy to the quantity of that item they wish to purchase</li></ul>The function should iterate over each item in the order and add the price to buy the desired quantity of that item to the total cost of the order. If any item in the order does not have a corresponding price, your function should raise a <code>KeyError</code>.<p>Once the cost of each item in the order has been calculated, the function should test to see if the overall cost for all items is greater than $100. If it is, a 10% discount should be applied to the overall cost. Otherwise, if the order is greater than $50, a 5% discount should be applied.</p><p>The overall cost of the order (after any applicable discounts) should then be returned by the function.</p><p>Write a function to meet these requirements.</p>"
exercise.code = "def calculate_price(price, order):\n\t# TODO: Implement this\n\tpass\n\nprice = {'book': 10.0, 'magazine': 5.5, 'newspaper': 2.0}\n\norder1 = {'book': 10}\norder2 = {'book': 1, 'magazine': 3}\norder3 = {'magazine': 5, 'book': 10}\n\nassert(95 == calculate_price(price, order1))\nassert(26.5 == calculate_price(price, order2))\nassert(114.75 == calculate_price(price, order3))\nprint(\"Done\")" exercise.code = "def calculate_price(price, order):\n # TODO: Implement this\n pass\n\nprice = {'book': 10.0, 'magazine': 5.5, 'newspaper': 2.0}\n\norder1 = {'book': 10}\norder2 = {'book': 1, 'magazine': 3}\norder3 = {'magazine': 5, 'book': 10}\n\nassert(95 == calculate_price(price, order1))\nassert(26.5 == calculate_price(price, order2))\nassert(114.75 == calculate_price(price, order3))\nprint(\"Done\")"
exercise.tests = [Test("Correct implementation", "Done\n")] exercise.tests = [Test("Correct implementation", "Done\n")]
exercise.checks = [Check("Please don't alter the assertions", "assert\\(95 == calculate_price\\(price, order1\\)\\)"), exercise.checks = [Check("Please don't alter the assertions", "assert\\(95 == calculate_price\\(price, order1\\)\\)"),
Check("Please don't alter the assertions", "assert\\(26.5 == calculate_price\\(price, order2\\)\\)"), Check("Please don't alter the assertions", "assert\\(26.5 == calculate_price\\(price, order2\\)\\)"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment