{"id":"printing-calculating","slug":"calculating","title":"Calculating with print","text":"`print` can show the result of a calculation as well as text. Write the calculation without quotes:\n\n```python\nprint(4 + 9)\nprint(6 * 7)\nprint(1 + 3 * 5)\n```\n\n```output\n13\n42\n16\n```\n\nPython uses `+` to add, `-` to subtract, `*` to multiply and `/` to divide. As in mathematics, multiplication and division come before addition and subtraction, so `1 + 3 * 5` is 16, not 20. Parentheses change the order: `(1 + 3) * 5` is 20.\n\n### Quotes or no quotes\n\nQuotes make all the difference. Without quotes, Python calculates. With quotes, the calculation is just text, printed exactly as it is written:\n\n```python\nprint(1 + 3 * 5)\nprint(\"1 + 3 * 5\")\n```\n\n```output\n16\n1 + 3 * 5\n```\n\nLetting Python do the arithmetic is safer than doing it in your head and typing the answer: `print(52 * 7)` is easy to read and easy to check, and Python never makes a slip.\n","task":"Fill in the blank with a calculation, so the program prints the number of seconds in an hour (60 seconds in a minute, 60 minutes in an hour).\n","kind":"fill","seed":"print(\"Seconds in an hour:\")\nprint([[60 * 60]])\n","solution":"print(\"Seconds in an hour:\")\nprint(60 * 60)\n","hints":["An hour has 60 minutes and each minute has 60 seconds, so multiply 60 by 60.","Multiplication is `*`: type `60 * 60` into the blank, without quotes."],"tests":[{"name":"Output","stdin":"","expect":"Seconds in an hour:\n3600","hidden":false}],"require":[],"forbid":[{"pattern":"\\b3600\\b","message":"Let Python do the arithmetic: write the calculation `60 * 60` instead of its result."}],"more":[{"task":"Write a program that prints the number of minutes in a week. Let Python calculate it from the number of days in a week, hours in a day and minutes in an hour. The program should print:\n\n```\nMinutes in a week:\n10080\n```\n","kind":"code","seed":"print(\"Minutes in a week:\")\n","solution":"print(\"Minutes in a week:\")\nprint(7 * 24 * 60)\n","hints":["A week has 7 days, a day has 24 hours and an hour has 60 minutes.","Multiply all three in one calculation: `print(7 * 24 * 60)`."],"tests":[{"name":"Output","stdin":"","expect":"Minutes in a week:\n10080","hidden":false}],"require":[{"pattern":"\\*","message":"Calculate the result with `*` (multiplication)."}],"forbid":[{"pattern":"\\b10080\\b","message":"Let Python do the arithmetic instead of typing the result 10080."}]},{"task":"What does this program print? Type each line it prints.\n","kind":"predict","seed":"print(\"4 + 4\")\nprint(4 + 4)\nprint((1 + 2) * 3)\n","solution":"print(\"4 + 4\")\nprint(4 + 4)\nprint((1 + 2) * 3)\n","hints":["The first line has quotes, so it's text and printed exactly as it is.","The second line has no quotes, so Python calculates 4 + 4.","The parentheses in the last line are calculated first, so it's 3 * 3."],"tests":[{"name":"Output","stdin":"","expect":"4 + 4\n8\n9","hidden":false}],"require":[],"forbid":[],"lines":["4 + 4","8","9"]}]}