This is the first homework where you'll write Python code, so the instructions are detailed and long. The actual problems are brief.
This homework assignment must be submitted in Gradescope by 10am CST on Wednesday, September 8, 2021.
This homework assignment is about the topics of worksheet 2, i.e. variables, the built-in types int, float, and string, and the use of booleans and conditionals.
No collaboration is permitted, and you may only access resources (books, online, etc.) listed below.
The course materials you may refer to for this homework are:
Expected to be most useful:
Allowed and possibly useful, but not the most relevant:
This homework assignment has 2 problems, numbered #2 and #3. Each problem is worth 4 points.
Because of the way Gradescope works, there will also be a problem 1 worth 0 points.
Ask your instructor or TA a question by email, in office hours, or on discord.
This is a Gradescope programming assignment, meaning that Gradescope will expect you to upload your
.py files. You need to upload both programs to Gradescope every time you submit. For advice on how to do that, see the section "Help submitting" below.
At the very end of this document there's some advice about how to work on these problems that duplicates things discussed in Lab 1, Worksheet 1, etc., but which might be helpful.
In Gradescope, problem 1 is used to report the result of autograder testing. In this homework, the autograder will ONLY give you advice (warn you of syntax issues etc.) but it won't actually assign any points. Everyone will get a full score (0 out of 0) on problem 1.
Write a program
hwk2prob2.py that waits for the user to type one line of text.
If the user types
Bumblebee (capital B) followed by the Enter key, the program should print
BUMBLEBEE DETECTED. Otherwise, it should print
Sample usage (first line is always what the user typed):
Bumblebee BUMBLEBEE DETECTED
Feral raccoon holding an improvised spear NO BUMBLEBEE
This line of text has Bumblebee in it but is not just that word by itself NO BUMBLEBEE
Write a program
hwk2prob3.py that asks the user for a base $b$ and exponent $x$ (both of them floats) and which then prints the value of $b^x$ (i.e. $b$ raised to the power $x$). You don't need to do any checking to make sure the input is valid.
The interface should look like this (two examples shown):
Base: 2.5 Exponent: 8 1525.87890625
8are values typed by the user.)
Base: 64 Exponent: 0.5 8.0
0.5are values typed by the user.)
IMPORTANT: Don't submit a program until you've tried it locally (on the computer you use to write programs) and you think it works.
This assignment requires you to upload 2 files every time you submit. Students sometimes find the Gradescope interface for multiple file uploads a little confusing, and end up submitting just one file. Here are detailed instructions:
Find "Homework 2" in Gradescope and click on it to submit.
This should open a window asking you to upload files, looking a bit like this:
Either drag both files onto the dotted box (e.g. from the explorer), or click on the dotted box to browse and select one file.
If you dragged both files into the dotted box, skip ahead to the last step.
If you browsed to select one file, you should now you should see a window looking like this:
To select a second file, click the link "Browse", which is marked with an arrow in the image above. It's not a button; it is a link in the middle of the dialog box.
Finally, when all your files appear in the window, click the large green "Upload" button.
Below is a summary of some things from worksheet 1 and the first couple of lectures about how to write and run Python programs. These are instructions for Windows. If you try to determine the corresponding steps for Mac of Linux and have trouble, let me know.
Create a folder to store your work.
Open Visual Studio Code and create a new file (
hwk2prob2.py). Save it in the folder you just created.
Open Windows Powershell
In Powershell, move to the folder with the new file. The easiest way to do that is to go back to Visual Studio Code, right-click the filename tab, and select "Copy Path". Go back to Visual Studio Code and paste the result. It will look something like this:
C:\Users\ddumas\Desktop\MCS 260\Homework 2\hwk2prob2.py
Edit that to a "cd" command that changes directory to the folder by adding
cd and a space at the beginning, putting quotes around the path, and removing the "hwk2prob2.py" filename:
cd "C:\Users\ddumas\Desktop\MCS 260\Homework 2\"
This is a command you only need to run once. Afterward, your Powershell will be opened in the correct folder and you can run the programs as many times as you need to.
Run the script
hwk2prob2.py by entering this command in Powershell:
Assuming that file is empty, you should either get a Powershell prompt back again immediately or you'll see an error. If you see an error, it probably means you are not in the correct folder.
Now, write some code in
hwk2prob2.py. When you think it will work, move on to...
Run the script
hwk2prob2.py again and test whether it works. Go back to step 6 if needed.
Create, write, and test