hypothes.is tag: s20iostpy01ualr
Download Assignment S2020Py01
Download Assignment LASTname_Fall2020_Py01
Students will be able to:
- Explain how to display data in Python using Thonny IDE
- Explain how to create a comment in Python
- Determine the difference between a string literal and a number
- Create print statements in Python3
- Create Python code that displays results to calculated addition and multiplication facts
Task 1: Update Anaconda
Your install of Anaconda is a fresh install, but there may have been updates to python libraries since the installation package was released. To update your anaconda package complete the following:
- In the start menu, type Anaconda to bring up the anaconda prompt. Click on the prompt to start anaconda.
This will bring up your anaconda prompt in a new command window.
2. Type conda update anaconda at the prompt and press enter (note: you may be prompted to type conda update -n base conda)
3. You will see that conda will determine what packages need to be updated. You should see a spinning cursor in the following window next to solving environment
4. There may or may not be packages that need to be updated. You can see in the screen below that there are many packages that need to be updated. Click y and enter to proceed:
5. You will see it updating as shown below. Specifically, you can see that the last line indicates that python needed to be updated. It will not download, extract and install updates. As it installs, the percent by each line will go from 0 to 100%
6. When it is complete, it will let you know:
Task 2- Watch video on Thonny:
Additional Thonny tutorials:
Model 1: Printing in Python
Output, one of the of the four main operations of a computer, is performed using a print statement in Python.
print("The atomic number") print("for carbon is") print("6")
The atomic number
In your Thonny python shell, type the first line of python code above and press enter.
Critical Thinking Questions:
- What does the first line of Python code in the Python program do?
- Circle the Python code’s equivalent representation in the flowchart.
- Using the Thonny python shell, enter and execute the following statements. What does the code produce when executed?
print("Hello, my name is Monty!")
- Was there a problem with any of the sample code in question 3? If so, what caused the problem?
- What caused the different formatting of output for samples “a” and “c” in question 3/
- Using the Thonny python shell, enter and execute the following statements. What do the following Python statements output?
Predict the results of each print statement and then using either the Thonny python shell on your computer or the Binder access to the LibreText Jupyter Hub validate your answers (you can cut and paste each question into the IDE/binder, the first one is already loaded)
- print (2+5)
- print (2*5)
- print ('2+5')
- print ("Age:",7)
- print ('Age:',2+5, "years")
- Answer a
- Answer b
- Answer c
- Answer d
- Answer e
Age: 7 years
a. print(2+5) b. print(2*5) c. print("2+5") d. print("Age:",20) e. print("Age:",2*10,"years")
- Examine the output for each statement in question 6.
a. What is the difference in the output for the statements in “a” and “c” of question 6?
b. What caused the difference?
c. Which of the statements contains a string literal?
d. What does the comma (,) do in the print statement in part “d” of question 6? How does it affect the spacing of the output?
e. Can you include both string literals and calculations in the same print statement? Explain.
Model 2: Documentation in Python
Documenting a program is essential for you as well as for others who may need to enhance or update your program at some future time. Any documentation or commenting in Python should begin with a “#”. The interpreter will ignore anything that comes after the “#” on a given line. See the example below.
# Programmer: Monty Python # Date: 3/15/2018 # Description: This program demonstrates the use of print # statements print("The mass of 0.5 moles of water is") print(0.5*18.02,"grams")
The mass of 0.5 moles of water is
Task 3: Run the program in Run current script mode.
In your Thonny IDE, choose File/New file.
In your Thonny IDE, choose File/Save and title the save file as Program1, and be sure to save as type “Python files”.
Copy the python program above into the editor window of your Thonny IDE.
Run the program by clicking the green run button , or hitting F5 of your function keys.
The output of the file will be shown in the shell window.
Task 4: Run the program again in debug mode.
To do so either go to menu Run/Debug current script or by clicking ctrl+F5
Critical Thinking Questions
- Examine the previous code and its output. What do the first four lines of the program do? (What did the python interpreter do with those four lines in debug mode?)
- What would happen if you placed a “#” in front of the code: print(0.5*18.02,"grams") in the previous program?
(after you predict what happens, put a # in front of the print statement, and rerun the program.)
Model 3: Computer system basic functions
There are four basic functions of a computer system:
The act of transferring information into the computer system. This can be achieved by using an input device (such as a keyboard or mouse), or through a previously stored program file.
The display of information from within the system to a user.
The manipulation and control of data.
The ability to save data in temporary and long-term repositories. Temporary data is stored in RAM, and long-term storage takes place on hard drives.
10. using what you have done today as a guide, provide examples of how you employed each of the four basic functions of a computer in this activity
Application Questions: Use the Thonny Python Editor and Shell windows to check your work
1. Create a Python program containing four statements to implement the flowchart in below. Write the statements next to the flowchart and test your work.
2. Create one line of Python code that produces the output expected from the flowchart in application question 1 except that it is outputted on only 1 line.
(e.g. your output will be The formula weight of cyclohexane is 84.16 g/mol.
3. Create a Python program containing two statements that prints the following output. Have the program calculate the answers to the two arithmetic problems.
At the top of this page you can download a Word document that you can do your assignment in and then upload to the Google Drive folder.
1) After reading the https://en.wikipedia.org/wiki/Flowchart, create a flowchart using https://www.draw.io/ that would describe heating a sample to constant mass. The following video is a nice overview of how to use it https://youtu.be/Z0D96ZikMkc) (5 points)
[Insert Image Here]
2) Create a Python program that prints out the following information and upload it as a python file with the following file name LastName_py01_Q2.py (the ".py" is the python file extension) (10 pts)
Line 1 prints out the name of an element and its atomic mass
Line 2 prints out the name of another element and its atomic mass
Line 3 prints out the value of the addition of the atomic masses of the two elements
Line 4 prints out the value of the product of the atomic masses of the two elements
Sample Printout for Hydrogen and Chlorine would look like:
Your program must contain documentation lines that include your name, the date, a line that states “Py01 Homework question 2” and a description line or two that indicates what the program is supposed to do. Take a screen shot of the program and the output and attach below:
[Insert Screenshot Here] (note, adjust all images so that they do not span a page break).
Python uses multiple data types. Using hypothes.is, find two different sites that describe data types in Python and write below a description of the difference between integers, floating point numbers and string literals. Be sure to tag the hypothes.is annotations with the chapter's tag: S20IOSTpy01ualr (case sensitive)
This work is licensed under a Creative Commons Attribution-NonCommercial-Shar