Part 1:
Exercise 1.1 from your textbook recommends that you try to make mistakes when experimenting with a new programming feature. This kind of experiment helps you remember what you read; it also helps when you are programming because you get to know what the error messages mean. It is better to make mistakes now and on purpose than later and accidentally. (Downey, 2015, 7) For this Learning Journal, first, answer the following questions based on Exercise 1.1. Include example Python code and output with your answers. • If you are trying to print a string, what happens if you leave out one of the quotation marks or both and why? • You can use a minus sign to make a negative number like -2. What happens for each of the following and why?
2++2 2--2 2+-2 2-+2 • In math notation, leading zeros are OK, as in 02. What happens if you try this in Python and why? • What happens if you have two values with no operator and a space in between them and why?
It seems like you're seeking answers related to Python programming based on Exercise 1.1 from a specific textbook. I can certainly help with that1. If you are trying to print a string and leave out one or quotation marks, you will receive a syntax error. For example:
Leaving out one quotation mark:
python print('Hello)
Output:
SyntaxError: EOL while scanning literal
NameError: name 'Hello' is not definedprint(Hello) Output:
a minus sign to make a negative number produces different results for each of the following:
2++2
: This would be interpreted as "2 + (+2)", resulting in 4
. When the second +
is encountered, it doesn't act as an but as a positive sign, so the two positive signs cancel other out.2--2
: This would be interpreted as "2 - (-)", resulting in 4
. Similar to the first case, two minus signs cancel each other out, effectively making a positive number.2+-2
: This would interpreted as "2 + (-2)", resulting in 0
. Here, the combination of and minus signs results in a subtraction operation.2-+2
: This would interpreted as "2 - (+2)", resulting in 0
. Similar to the previous case, the combination of minus and plus signs results in a subtraction operation.In Python, leading zeros are not allowed when specifying numeric literals. If you try to use leading zeros, you will receive a syntax error. For example: python x = 02
Output:
Syntax: leading zeros in decimal integer literals are not permitted; use an 0o prefix for oct integers
If you have two values no operator and a space in between them, you would get a syntax error. For example:
x = 7
Output:
SyntaxError: syntax
Python expects an operator (such as +, -, *, /, etc.) in between values for an expression to be valid.
I hope this helps! If you have any questions or need further assistance, feel free to ask.