The objective of this mini-lab is to become familiar with the programming environment VSCode and the language Python, which will both be used in COMP107.
CS107Labs
.
CS107Labs
folder, to start working. (Alternatively, you can close the Start
window, and then go to File -> Open folder to select your CS107
Labs
folder.)GettingStartedML.py
. Be sure to
add the .py
ending so that your file is identified as a
Python file!print(3 + 4)
print(3 - 4)
print(3 * 4)
print(3 ** 4)
print(3 / 4)
print(3 // 4)
print(3 + 4)
print(3 + 4)Include the results in your submission. Detail whether the operations were expected. For those which were not, provide an explanation for what is occuring.
Jes4py
library. We will tell our program to use this
library by adding the following statement at the very beginning of
your program:
from jes4py import *
myFile = pickAFile()
A file selector will open. Choose a JPEG (.jpg) file from a folder on
your hard drive. (Or, if you prefer a
wider selection of images, copy several images from the MediaSources
directory to a folder on your own hard drive.)pickAFile()
doing? Did you see anything new
happen when you ran the program?
Write down your answer in a complete sentence in a Word document or in
the markdown file provided above.print(myFile)
below your previous statement and run the program again.
What is printed? Using sentences, write down the result and explain
what this command is doing.myPict = makePicture(myFile)
at
the end of your program and run the program.
What did you see happen? Write down what iyou think this function is doing. If
you're not sure, ask an instructor or a TA.print(myPict)
to the end of your
program. What is printed?
Write down your result.show(myPict)
to the end of your program and run your program. A new window should
appear with your picture displayed, but you probably didn't see it
happen.Jes4py
, add
the statement:
from time import *
and then add
the line sleep(5)
after your show
statement.
Now when you run your program your picture should be displayed for 5
seconds.writePictureTo(myPict, pickAFile())
In the file selector, select the image you had chosen earlier.
writePictureTo(myPict, pickAFolder()+"chooseAName.jpg")
Prior to running, make sure chooseAName is a different name from your original image file. In the folder selector window, select the folder you have your original image in.
pickAFile
function to select a
sound file. Add the following line of code to the end of your
program.
soundFile = pickAFile()
When the file chooser window opens, select a sound file. (Note: sound
files have a .wav
extension.)sound = makeSound(soundFile)
to
your program.blockingPlay
function. Add this statement to the end of your program:
blockingPlay(sound)
.
If nothing happens, make sure that the volume isn't turned all the way down on your computer.