import random # for generating random values
import time # for pausing execution
import sys # needed for pausing component
# to work
# Here, DELAY represents the pause length,
# in seconds, after each * is printed
#
# For example, 0.05 would be 50 milliseconds
#
# If you like, you can change the value of
# this constant to something else, though I
# would not go over 0.5.
DELAY = 0.05
count = 0 # Number files downloaded
answer = "yes" # User response to
# prompt to continue
# YOUR CODE STARTS HERE
# YOUR CODE ENDS HERE
print ()
print ("You downloaded", count, "files, total.")
Your will need to do the following things:
- Declare and initialize whatever variables you need for the program. (Already done for you.)
- Your program will have two loops, one nested inside the other.
- Your outer loop (Should this loop be a while or a for?) is responsible the following sequence of events:
- Generating a random file size between 10 million and 100 million. You will want to store this figure in a variable.
- Downloading the file. (See Step 4 below!)
- Printing the string COMPLETE!
- Updating the number of files downloaded so far.
- Asking if the user wants to download another file, and altering a value accordingly such that the outer loop eventually stops, depending on the user's response.
- Your inner loop (Should this loop be a while or a for?) is what downloads the file. This involves printing a * character (without skipping to the next line) for each 1 million (of the file's total size) that gets downloaded and keeping track of the progress on downloading the file (so that you know when the download is complete.).
If you want your program to behave like the in-class demonstration, after you print the * character, include the following two lines of code:
sys.stdout.flush()
time.sleep(DELAY)
- At the end, your program reports how many files total the user downloaded. (Already done for you.)
Note that because of user input and random values, the output will look different each time you run the program.
Program output example:
+ Expand Output
Downloading a file of 15149154 bytes.
****************COMPLETE!
Another file? YES
Downloading a file of 32114196 bytes.
*********************************COMPLETE!
Another file? YES
Downloading a file of 49946355 bytes.
...
- Collapse Output
Downloading a file of 15149154 bytes.
****************COMPLETE!
Another file? YES
Downloading a file of 32114196 bytes.
*********************************COMPLETE!
Another file? YES
Downloading a file of 49946355 bytes.
**************************************************COMPLETE!
Another file? YES
Downloading a file of 70525001 bytes.
***********************************************************************COMPLETE!
Another file? YES
Downloading a file of 74457562 bytes.
***************************************************************************COMPLETE!
Another file? YES
Downloading a file of 88362658 bytes.
*****************************************************************************************COMPLETE!
Another file? YES
Downloading a file of 63952457 bytes.
****************************************************************COMPLETE!
Another file? YES
Downloading a file of 70083793 bytes.
***********************************************************************COMPLETE!
Another file? YES
Downloading a file of 22587856 bytes.
***********************COMPLETE!
Another file? YES
Downloading a file of 92608938 bytes.
*********************************************************************************************COMPLETE!
Another file? YES
Downloading a file of 55043669 bytes.
********************************************************COMPLETE!
Another file? YES
Downloading a file of 42656083 bytes.
*******************************************COMPLETE!
Another file? YES
Downloading a file of 95922137 bytes.
************************************************************************************************COMPLETE!
Another file? YES
Downloading a file of 27843717 bytes.
****************************COMPLETE!
Another file? YES
Downloading a file of 66949868 bytes.
*******************************************************************COMPLETE!
Another file? NO
You downloaded 15 files, total.
In at least 150 words, please address the following questions in memo.txt: - How did the process of creating these programs go for you?
- What were your main challenges and how did you overcome them?
- What did you learn that may be of use as you move along in this class?