Due: Wednesday, February 7, 8pm
Experiments with search. Download this
file unit1_lesson2_data
To do that, you can right-click on that link and click "Save
Link As..." or "Download Linked File As..." (depending on what
browser you are using) then navigate to
your Unit 1 Lesson 2
folder and
name the file "unit1_lesson2_data.py". Make sure that you
set the file extension
to .py
. (For security reasons, my
webserver will not allow me to link you to
a .py
file directly, so you have to
add this file extension yourself when saving.)
Create a new file in VS Code for this part of the homework. Call it "unit1_hw1_part1.py". At the top, add the following line:
from unit1_lesson2_data import *Now,
number_list
will be a variable that you can
use in your code. This variable contains a list of 1,000
numbers between 0 and 1000. Use this for the following
exercises. You can put each in the same file, or create new
files for each. In any case, after you run your code and find
the answer to the question, put that in your code as a
comment #
.
Write some code to find the smallest number in this list. What is it?
Write some code to find the smallest number in this list that is greater that 500. What is it?
The modulo operator %
tells you the remainder
when one number is divided by another. So 10 %
3
equals 1. You can use this to check if a number
is even or odd. For example, if x % 2
is
equal to 0, then x
is even. If x %
2
equals 1, then x
is odd. Use this to
write code to find the smallest even number in
this list. What is it?
You have also imported a variable
called word_list
which contains 50 random
words. Write some code to find the word in this list that
is last alphabetically. What is it?
Write code to find the word that is longest. Hint: you can use len()
to find the length of a word. What is it?
If you still have not yet done so, read the page about asking for help on the class website. You must then follow the instructions there to create a Gist account if you don't already have one. Then create a new Gist and share it with me. Include your name in your comment, so I can make a record of your GitHub username.
If you haven't encountered any coding problems this week (that's great!) just share one of your code files with a note saying that everything is working. The goal here is to test out Gist and make sure that we'll be able to use it this semester.