Programming Fundamentals Learning Journal Unit 1 PDF

Title Programming Fundamentals Learning Journal Unit 1
Course Fundamental Programming
Institution University of the People
Pages 3
File Size 54.3 KB
File Type PDF
Total Downloads 82
Total Views 143

Summary

Programming fundamentals learning journal unit 1 . unit 1 assignment. cs1101....


Description

Indeed, I agree with the textbook's recommendation that we should try to make mistakes when experimenting with a new programming feature (Downey, 2015). In this assignment, I used python anywhere website to run the codes and my output and findings are given below. Experiment 1. When trying to print a string, what happened when I left out one of the quotation marks was that the interpreter replied with syntax error as given below: >>>print('dolla) File "" , line 1 print ('dolla) SyntaxError: EOL while scanning string literal When I left out both quotation marks while trying to print a string, the interpreter also replied with syntax error as given below: >>>print(dolla) Traceback: (most recent call): File "" , line 1, in NameError: name 'dolla' is not defined Conclusion. From the experiments above its clear that this kind of error in python seems common and care should be taken to avoid it. This is simply because when the string is not in enclosed by quotation marks in the print statement, the system will give you an error. Experiment 2 >>>2++2 4 >>>2--2 5 >>>2+-2 0 >>>2-+2 0 Conclusion. This experiment raised my curiosity a little bit as I had to understand what is going on. Experiment 3 In math notation, leading zeros are OK, as in 02. When I tried this in Python however, the system gave me an error as illustrated below: >>>02 File "" , line 1 02 SyntaxError: invalid token Conclusion. From the experiment above, leading zeros are not allowed in Python as the system will give you SyntaxError. Experiment 4 When i entered two values with no operator and a space in between them, the system gave me an error as illustrated below:

>>>2 2 File "" , line 1 22 SyntaxError: invalid syntax Conclusion. From the experiment above, it's clear that having spaces between values with no operator between them will give you a SyntaxError. Therefore, care should be taken to avoid this kind of error. Part 2. The following are the three additional Python experiments that I tried while learning Chapter 1 of the reading assignment: Experiment 1. >>>x=5 >>>y=6 >>>x+y 11 >>>x*y 30 Explanation. From this experiment I learnt that you can assign values to letters and use them in calculations later. Experiment 2. >>>f=8 >>>F Traceback: (most recent call): File "" , line 1, in NameError: name 'F' is not defined >>>f 8 Explanation. From the experiment above, I learnt that when assigning values to letters, extreme care should be taken in the letters cases. If it was in upper case, entering the same letter in lower case will give you an error. Experiment 3. >>>type(0.123)

>>>type('0.123')

Explanation. From the experiment above it's clear that a number can be a floating point number but when quotation marks are involved the number becomes a string. Therefore care should be taken in punctuation to make sure you enter the correct input.

Reference: 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). https://my.uopeople.edu/pluginfile.php/1546089/mod_page/content/3/TEXT%20-%20Think%20 Python%202e.pdf...


Similar Free PDFs