Exercise 1
An Everyday Algorithm
Create a text file algorithm.txt
with your answer to this part.
Give an example of an everyday algorithm (other than the ones discussed in lecture).
Check your algorithm against the four criteria listed from the definition of "algorithm". Indicate how it does/doesn't meet each of them.
Hello World
Make sure you have Python installed, or are on a computer (like in CSIL) that already has it.
Start IDLE and create a Python program named hello.py
prints the words "Hello world" on the screen when it's executed. [Yes, we did this in lecture. The point is for you to make sure you can use the tools.]
Make sure you're doing this in an editor window in IDLE, not in the interactive interpreter. You should be able to save what you typed as a .py
file.
Variables
Create a Python program variables.py
that sets the following variables to the corresponding values and then prints the contents of each of the variables.
Variable Name | Value |
---|---|
course |
"CMPT 120" |
credits |
3 |
pi |
3.1416 |
Some tests
Create a text file output.txt
with your answer for this part.
What is printed by each of these statements? Do this without typing the code. You can confirm your answer with the IDLE interactive interpreter if you like.
print("Hello" + " " + "World")
print("The sum: " + str(4+5+6))
print(15 / 4)
print(15 // 4)
print(round(15.0/4))
Submitting
Submit all of your work through CourSys.