Almost every week, we will do three things before starting to work on the lab exercise. You did them last week, too.
First, create a directory on your USB device for this lab, say, lab02 as a sub-directory inside your cs1510 directory.
Next, launch IDLE, the program that provides us with a Python shell and a Python-savvy program editor. You can find IDLE by selecting Start | All Programs | Python 3.4 | IDLE (Python GUI). This will start you off with a Python shell window. At the end of the session, you will save your shell window as a transcript of your interactions throughout the lab.
Finally, open a new text file called responses.txt using whatever editor you like. You will use it to record answers and questions as you work through the lab.
You have learned that computers ultimately use the binary digits 0 and 1 to represent all data. So, every character can be given a number as a code. This includes letters such as a and Z, punctuation marks such as # and @, and even characters like the space and "new line". The first standardized set of characters was ASCII. It is the basis today for a more extensive coding, Unicode.
In Python, you can find out the decimal equivalent of any character using the ord() function:
>>> ord('a') 97
To find out which character corresponds to a particular decimal number, use the chr() function:
>>> chr(66) 'B'
Now, use these functions in your Python shell to answer these questions:
You may evaluate as many Python expressions as you would like to answer each question. However, you may use only these Python operators and functions:
+ addition - subtraction ord() ASCII value for a character chr() character for an ASCII value
If think you want or need to use something else, ask me first.
Record your answers in responses.txt.
You have learned that computer scientists often use binary numbers to represent numbers, because this mimics how computers are built out of transistors. Binary numbers use 2 as the base for counting.
With only two digits, 0 and 1, binary numbers grow very long very quickly. For convenience, computer scientists sometimes use hexadecimal numbers as a shorthand. Hexadecimal numbers use 16 as the base for counting. 16 = 24, so "hex" has all of the advantages of base 2 and plus the extra advantage of shorter numbers. (Even shorter than decimal!)
If you would like a refresher, take a look at one or more of these short tuturials:
Now, evaluate a series of expressions in your Python shell to answer each of these questions:
You may evaluate as many Python expressions as you would like to answer each question. However, you may use only these Python operators:
// integer division % integer remainder * multiplication ** exponentiation
If think you want or need to use something else, ask me first.
Record your answers in responses.txt.
Time permitting, let's solve a real problem with a little Python code.
A friend is planning a trip to Europe. Her bank will exchange US dollars for euros for a $10 service fee. It converts the rest of the dollars to euros at the current exchange rate. As of this morning, the exchange rate is 1 euro for 1.31 US dollars.
For example, if your friend wants to exchange $100, the bank will keep $10 and give your friend $90 / 1.31 = 68.70 euros.
Open a new program window by selecting File | New File. In it, write a short program that:
Feel free to use seconds_left.py from class as a template. You can also use the shell to test out expressions before copying them to your program window.
Try your program out on the example above, plus a couple others of your choosing.
Save your program in a file called currency_converter.py. Don't worry about putting a full header block in, but please do add a comment that contains your name.
Make sure that your responses file and program file are complete and saved. Save your shell window to a file called transcript.py.
Now, let's submit your files for grading:
Uploading the following files. transcript.py of size 1467 bytes responses.txt of size 716 bytes currency_converter.py of size 416 bytes The files listed above were uploaded. You are responsible to make sure that this list is complete. You may replace or add file up until the deadline by using this system again...
If you need any help, let me know.