Learning journal unit 1 CS1001 PDF

Title Learning journal unit 1 CS1001
Author Michele Lecca
Course Programming Fundamentals
Institution University of the People
Pages 3
File Size 122.1 KB
File Type PDF
Total Downloads 56
Total Views 138

Summary

LJ unit 1 CS 1101...


Description

Learning journal unit 1 Part 1: • If you are trying to print a string, what happens if you leave out one of the quotation marks or both and why? For this exercise there are multiple combinations: >>> print("Hello World!) SyntaxError: EOL while scanning string literal In this case, seems that the Python interpreter expected a particular character but those characters were not found before the end of the line (EOL) and neither the end of the parenthesis. >>> print(Hello World!") SyntaxError: invalid syntax In this case, it just gives an invalid syntax because print as a function needs to use both parenthesis and by putting the quote at the end of our message it transform the parenthesis in the string thus invalidating the function print. • You can use a minus sign to make a negative number like -2. What happens for each of the following and why? >>> 2++2 4 In this case, there is a simple addition. >>> 2--2

4 In this case, it seems like the Python interpreter sum the number but also, calculate the positivity or the negativity of the number by multiplying the sign in this case - * - = + It would give the same the result if we try this: >>> 2-(-2) 4 If we wanna sum two negative number we need to use parenthesis like this: >>> (-6)+(-8) -14 >>> 2+-2 0 In this case, we have an addiction of the same number being the first one positive and the second one negative. >>> 2-+2 0 For this case we have a sottraction of the same number been both positive.

• In math notation, leading zeros are OK, as in 02. What happens if you try this in

Python and why? >>> 02 SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers Python in need to use both Decimal and Octal system needed to imply some rule to be sure to recognize what kind of system number we are using, as default we use the Decimal system. If we wanna use Octal system we need to use the prefix 0o for octal integers like this: >>> 0o02 2 • What happens if you have two values with no operator and a space in between them and why? >>> 2 2 SyntaxError: invalid syntax In this case, the Python doesn't understand the space in between the number and do not have enough information on how to process the input that we are sending.

Part 2: Examples that I tried by myself: >>> print("print('hello world')") print('hello world') Air quotes are the components that we need to use to give the input to the Python interpreter to understand when the string starts and when it ends, so the single quote inside of the double quotes is not a input recognized from the system instead is just a part of the string that we are getting as output. >>> 0o00000009 SyntaxError: invalid digit '9' in octal literal I wanted to try and see what would happen if I used a bigger single digit number than 7 and as I thought it gives an error because with the 0o prefix we decide to use Octal system and that system works from 0 – 7 so it's normal that we receive an error.

>>> print("Hello " + "World" + "!") Hello World! I wanted to try to sum a string, but as I noticed the space that are not inside of the air quotes are just for the clear view of the reader of the code, because it will not show any space that is not inside of the air quotes.

References: Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press. This book is licensed under Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0). Navone Estefania Cassingena, E.C:N. (2019) Leading Zeros in Python: A Hidden Mystery Revealed. Retrieved from: https://medium.com/techmacademy/leading-zeros-in-python-a-hidden-

mystery-revealed-ee3e3065634d...


Similar Free PDFs