Blog
Opening and manipulating files
CSCE 101 Lab 7
Opening and manipulating files
Academic Honesty
The work you turn in is to be your work, not copied from someone else or from the web.
Never allow anyone access to your files.
Never give anyone your password.
Never share your flash drive or email your files to anyone.
Never give anyone a printed copy of your file or an electronic copy.
Never allow anyone to copy your work.
General information
Read the entire assignment before you start.
We will be writing programs using Python 3. Please be sure to download and install the latest version of Python 3, if you have not already done this. Python for both Windows and Mac is available at: HYPERLINK “https://www.python.org/downloads/” https://www.python.org/downloads/
When you are in the lab, always work from your X: Drive on a computer in the lab, and copy your files you complete during the lab to your personal flash drive at the end of your lab class and every time you work on your assignments from a computer in the lab.
You have already created a folder named CSCE101 where you save your files on your X: drive. The instructors have READ ONLY permission to your X drive. They can see all of your files but cannot change anything on your X drive.
You must turn in a printed copy of the code for both Part A and Part B at the beginning of lab class in order to receive a grade for this lab assignment. Your files that you save on the X: Drive by the deadline must match the paper copies of Part A and Part B that you turn in to your lab instructor at the beginning of lab.
As a general reminder, always maintain backup copies of your work and remember to save frequently as you are working (in case of power outage, computer locking up, etc.).
The printers in the 244 and the 361 labs in the Sumwalt College Building are for printing CSCE 101 or 102 material only. It is not for printing notes, etc. for other classes or from the web, 101/102 only. The College of Engineering and Computing is keeping track of the number of pages that you use and can revoke your account for misuse.
If you click on the home drive icon on the desktop and do not click anything else and can see your 101 Lab folder in the open folder than your folder is in the correct place. If you then click on your 101 folder and without clicking anything else, you see your files, then your files are in the right place. Your Home drive is the xdrive.
All sections with the exception of section 1, should have two Blackboard pages. a Supersite for lecture and the regular one for lab. Look for the Supersite.
If you are not in section 1 and do not have two blackboard pages for this course, please email both your lecture and lab instructors today!
Please remember that copying from the web is cheating and is a violation of Academic Integrity. You are to write your own code. Help is available! We will be posting more open hours all week so refresh the Open Hours Schedule page every time you open it.
Part A
Reading from files (lab7_XX.py):
In this lab you will need to take a test file (included on blackboard as lab07_python.txt)
Remember the test file you will be reading in needs to be in the same folder as your lab7_XX.py file.
You will be using the Python IDLE (a Python editor and programming environment that comes with python). Name your file lab7_XX.py where you replace the XX with your initials.
Your program must include:
A comment on the top line of your program containing your name.
A comment on the second line containing your section number.
A comment on the third line containing the date.
A comment on the fourth line containing your email address.
A comment with the lab number and purpose of this lab.
Write a python program to open the test file provided. You will read in the numbers contained in the file and provide a total for the numbers as well as the largest and smallest number you encounter. Note: one method to keep track of the largest and smallest number is to include a pair of if statements in your loop reading in the file. If you encounter a number larger than the largest you have seen so far, replace the “largest” with the new value. You can handle the “smallest” in a similar fashion. You will need a variable to keep track of the largest and smallest numbers you encounter. No values in the test file will be smaller than zero or larger than 10000.
Output a message with the total, largest and smallest numbers as well as the average of all the numbers in the file.
Output a message to the user thanking them from using your program that includes your first and last name.
*****
Reminder: for this assignment, make sure you include both your .py file and the test file lab7_python.txt in the same folder of Xdrive. Make sure your code is runnable in Xdrive.
******
Part B
Turtles Red versus Blue (lab7_XX_turtle.py):
In this section of the lab we will be writing expanding on the program from lab 5 that creates a turtle and allows you to control it with the keyboard as it moves about the screen.
You will be using the Python IDLE (a Python editor and programming environment that comes with python). Name your file lab7_XX_turtle.py where you replace the XX with your initials.
Your (turtle) program must include:
A comment on the top line of your program containing your name.
A comment on the second line containing your section number.
A comment on the third line containing the date.
A comment on the fourth line containing your email address.
A comment with the lab number and purpose of this lab.
Don’t forget to include import turtle on a line after the comments so you can use the various Turtle-related objects and methods.
Create five Red turtles and five Blue turtles using one or more lists.
Start each of the Red turtles at a different random location on the left side of the screen within the range of the square formed by x coordinate(-100, 0) and y coordinate(-100, 100) and each of the Blue turtles at a random location on the right side of the screen within the range of the square formed by x coordinate (0, 100) and y coordinate (-100, 100).
Each of the red and blue turtles should move randomly (change direction each 60 moves).
Draw a boundary for the game as a circle with a 300 unit radius. You will use an invisible turtle to do this. It does not count as one of the turtles on either team.
If a turtle hits the border the turtle should have its color changed to yellow and should jump back to the center of the screen (0, 0) and continue moving.
All the turtles will move the same speed and without leave a line behind.
The turtles should continue moving until 1000 time units have elapsed.
