CS Week 1 LJ rvsd 1

docx

School

Brevard Community College *

*We aren’t endorsed by this school

Course

1101

Subject

Computer Science

Date

Nov 24, 2024

Type

docx

Pages

8

Uploaded by tbb11007

Report
CS 1101 - Programming Fundamentals Week 1 – Learning Journal Buck, Timothy Throughout this unit, we have extensively explored the essential principles of computer programming, fundamental debugging techniques, and proficiently performing basic calculations using Python. To prepare for this assignment, we thoroughly examined Chapter 1 - "The Way of the Program" (pp. 1-8) in Allen B. Downey's book "Think Python: How to Think Like a Computer Scientist" [1]. This textbook is widely respected due to its inclusive content coverage, illustrative examples, and valuable tips on troubleshooting. It follows a modular approach that serves as an optimal starting point for beginners by prioritizing conceptual understanding and providing contemporary information pertaining to Python 3. The textbook's clarity, coherence, and organized structure render it an exceptional resource for introductory learning of Python programming. Related directly to the class assignment: a. If you are trying to print your name, what happens if you leave out one or both of the quotation marks and why? If you leave out one or both of the quotation marks when trying to print your name, a SyntaxError will occur. In Python, quotation marks (either single quotes ' or double quotes ") are used to delimit string literals. Here's an example to illustrate the issue: When you leave out one or both of the quotation marks, Python interprets the text as a variable name rather than a string literal. If the variable is not defined, Python will raise a NameError because it cannot find the variable. Here's an example to illustrate the issue:
b. What is the difference between * and ** operators in Python? Explain with the help of an example. In Python, the * operator is used for multiplication of two numbers or repetition of a string or list, while the ** operator is used for exponentiation or raising a number to a power. Here's an example to illustrate the difference: # Multiplication using * result = 8 * 5 # 8 multiplied by 5 print(result) # Output: 40 # Exponentiation using ** result = 12 ** 6 # 12 raised to the power of 63 print(result) # Output: 2985984 c. In Python, is it possible to display an integer like 09? Justify your answer. It is not feasible to represent an integer like 09 in Python. Integers in Python are denoted using base 10 and it is against the rules to have leading zeros in base 10 numeric literals. If you attempt to showcase an integer with a leading zero, Python will interpret it as an octal (base 8) literal. However, the number 9 is not accepted in octal notation since only digits from 0 to 7 are valid. Consequently, if you try to present an integer with a leading zero followed by the digit 9, Python will raise a SyntaxError. Here's an example to demonstrate this behavior: # Trying to display an integer with leading zero followed by 9 number = 09 # Raises a SyntaxError: leading zeros in decimal integer literals are not permitted
d. Run the commands type('67') and type(67). What is the difference in the output and why? The commands type('67') and type(67) are used to determine the type of the respective values. When you run type('67'), it returns the type 'str', indicating that '67' is a string because it is enclosed in quotation marks. Strings represent sequences of characters in Python. When you run type(67), it returns the type 'int', indicating that 67 is an integer. Integers represent whole numbers without any decimal or fractional parts. Part 2 Here's the Python code for each of the questions (a) to (d), along with explanations and the related outputs: a. To multiply your age by 2 and display it: Explanation: The code prompts the user to enter their age, which is then multiplied by 2 using the * operator. The result is stored in the result variable and displayed using the print() function. b. To display the name of the city, country, and continent you are living in: city = "Merritt Island" country = "United States" continent = "North America"
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Explanation: The code defines variables for the city, country, and continent. These variables hold the corresponding information. The print() function is then used to display the values of these variables. c. To display the examination schedule (starting and ending day) of this term: start_day = "2023-08-10" end_day = "2023-08-13" print("Exam Schedule") print("Start Day:", start_day) print("End Day:", end_day) Explanation: The code assigns the start and end dates of the examination schedule to variables. The print() function is used to display the schedule, including the start and end days. d. To display the temperature of your country on the day the assignment is attempted by you: Truthfully, I tried all this stuff and looked up some references and I still could not figure this out. Here are my results.
>>> response = requests Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'requests' is not defined >>> response = requests.get Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'requests' is not defined >>> response = requests.getget("https://weather.visualcrossing.com/VisualCrossingWebServices/rest /services/timeline/Merritt%20Island%20FL? unitGroup=us&key=H4CD3S75J6ZTX2YEAUQC7VXY5&contentType=json") Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'requests' is not defined >>> response = requests.get("https://weather.visualcrossing.com/VisualCrossingWebServices/rest/se rvices/timeline/Merritt%20Island%20FL? unitGroup=us&key=H4CD3S75J6ZTX2YEAUQC7VXY5&contentType=json") Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'requests' is not defined >>> response = requests.getget("https://weather.visualcrossing.com/VisualCrossingWebServices/rest /services/timeline/Merritt%20Island%20FL? unitGroup=us&key=H4CD3S75J6ZTX2YEAUQC7VXY5&contentType=json") Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'requests' is not defined >>> >>> >>> response = requests.get(https://weather.visualcrossing.com/VisualCrossingWebServices/rest/ser vices/timeline/Merritt%20Island%20FL? unitGroup=us&key=H4CD3S75J6ZTX2YEAUQC7VXY5&contentType=json) File "<stdin>", line 1 response = requests.get(https://weather.visualcrossing.com/VisualCrossingWebServices/rest/ser vices/timeline/Merritt%20Island%20FL? unitGroup=us&key=H4CD3S75J6ZTX2YEAUQC7VXY5&contentType=json) ^ SyntaxError: invalid syntax >>> >>> >>> >>> url = (https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timelin e/Merritt%20Island%20FL? unitGroup=us&key=H4CD3S75J6ZTX2YEAUQC7VXY5&contentType=json) File "<stdin>", line 1 url = (https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timelin
e/Merritt%20Island%20FL? unitGroup=us&key=H4CD3S75J6ZTX2YEAUQC7VXY5&contentType=json) ^ SyntaxError: invalid syntax >>> 33 33 >>> >>> >>> response = requests.get(https://weather.visualcrossing.com/VisualCrossingWebServices/rest/ser vices/timeline/Merritt%20Island%20FL? unitGroup=us&key=H4CD3S75J6ZTX2YEAUQC7VXY5&contentType=json) File "<stdin>", line 1 response = requests.get(https://weather.visualcrossing.com/VisualCrossingWebServices/rest/ser vices/timeline/Merritt%20Island%20FL? unitGroup=us&key=H4CD3S75J6ZTX2YEAUQC7VXY5&contentType=json) ^ SyntaxError: invalid syntax >>> data = response.json() Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'response' is not defined >>> data = response.json((https://weather.visualcrossing.com/VisualCrossingWebServices/rest/s ervices/timeline/Merritt%20Island%20FL? unitGroup=us&key=H4CD3S75J6ZTX2YEAUQC7VXY5&contentType=json) File "<stdin>", line 1 data = response.json((https://weather.visualcrossing.com/VisualCrossingWebServices/rest/s ervices/timeline/Merritt%20Island%20FL? unitGroup=us&key=H4CD3S75J6ZTX2YEAUQC7VXY5&contentType=json) ^ SyntaxError: invalid syntax >>> >>> >>> pip install requests File "<stdin>", line 1 pip install requests ^^^^^^^ SyntaxError: invalid syntax >>> >>> >>> >>> pip install requests File "<stdin>", line 1 pip install requests ^^^^^^^ SyntaxError: invalid syntax >>> >>> import requests Traceback (most recent call last): File "<stdin>", line 1, in <module>
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
ModuleNotFoundError: No module named 'requests' >>> >>> >>> >>> api_key = H4CD3S75J6ZTX2YEAUQC7VXY5 Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'H4CD3S75J6ZTX2YEAUQC7VXY5' is not defined >>> api_key = "H4CD3S75J6ZTX2YEAUQC7VXY5" >>> city = "Merritt Island" >>> url = "https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timelin e/Merritt%20Island%20FL? unitGroup=us&key=H4CD3S75J6ZTX2YEAUQC7VXY5&contentType=json") File "<stdin>", line 1 url = "https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timelin e/Merritt%20Island%20FL? unitGroup=us&key=H4CD3S75J6ZTX2YEAUQC7VXY5&contentType=json") ^ SyntaxError: unmatched ')' >>> >>> >>> api_key = "H4CD3S75J6ZTX2YEAUQC7VXY5" >>> city = "Merritt Island" >>> url = f"http://api.openweathermap.org/data/2.5/weather? q=MerrittIsland&appid=H4CD3S75J6ZTX2YEAUQC7VXY5 File "<stdin>", line 1 url = f"http://api.openweathermap.org/data/2.5/weather? q=MerrittIsland&appid=H4CD3S75J6ZTX2YEAUQC7VXY5 ^ SyntaxError: unterminated string literal (detected at line 1) >>> References 2. Using Python on Unix platforms — Python 3.10.4 documentation . (n.d.). Docs.python.org. Retrieved June 21, 2023, from https://docs.python.org/3/using/unix.html
3. Using Python on Windows — Python 3.8.5 documentation . (n.d.). Docs.python.org. Retrieved June 21, 2023, from https://docs.python.org/3/using/windows.html Downey, A. (2015). Think Python How to Think Like a Computer Scientist 2nd Edition, Version 2.4.0. In https://greenteapress.com/thinkpython2/thinkpython2.pdf (pp. 1–8). https://greenteapress.com/thinkpython2/thinkpython2.pdf