exit(0).
open() fails, an OSError exception will be raised.
Check the documentation.
split() many times.
in operation to see if a keyword is in a given dictionary.
File not found! and exit.
add amt lbs name
—
which adds amt lbs of fruit name to
the current orderError! name not found!
price name
—
which prints the price of the fruit name
formatted as in this example:
blueberries are $1.59 per pound
Error! name not found!
checkout
—
which exits the program, printing out the total price
of the order in the format: total is $num
| Sample Runs | ||
~/$ python3 p1.py Filename: fruit1.txt command: add 3 lbs mango command: price asdf Error! asdf not found! command: price peaches Error! peaches not found! command: price blueberries blueberries are $1.59 per pound command: add 2.1 lbs blueberries command: checkout total is $5.469 |
~/$ python3 p1.py Filename: fruit2.txt command: add 2.0 lbs oranges command: price kiwi kiwi are $1.07 per pound command: price starfruit Error! starfruit not found! command: add 1.5 lbs peas Error! peas not found! command: add 1.5 lbs plums command: checkout total is $2.505 |
~/$ python3 p1.py Filename: foobar.txt File not found! |
hexdump a useful utility program that shows the contents of a file
in binary and text form.
Download ex1_test.py and two.pcap.
$ cat ex1_test.py from ex1 import * a = 0b11010101 pr(a) b = zero_out_top(a, 3) pr(b) c = set_one_at(a, 2) pr(c) d = set_zero_at(a, 1) pr(d) $ hexdump -C ex1_test.py 00000000 66 72 6f 6d 20 65 78 31 20 69 6d 70 6f 72 74 20 |from ex1 import | 00000010 2a 0a 61 20 3d 20 30 62 31 31 30 31 30 31 30 31 |*.a = 0b11010101| 00000020 0a 70 72 28 61 29 0a 62 20 3d 20 7a 65 72 6f 5f |.pr(a).b = zero_| 00000030 6f 75 74 5f 74 6f 70 28 61 2c 20 33 29 0a 70 72 |out_top(a, 3).pr| 00000040 28 62 29 0a 63 20 3d 20 73 65 74 5f 6f 6e 65 5f |(b).c = set_one_| 00000050 61 74 28 61 2c 20 32 29 0a 70 72 28 63 29 0a 64 |at(a, 2).pr(c).d| 00000060 20 3d 20 73 65 74 5f 7a 65 72 6f 5f 61 74 28 61 | = set_zero_at(a| 00000070 2c 20 31 29 0a 70 72 28 64 29 0a 0a 0a |, 1).pr(d)...| 0000007d
hexdump does. A sample run:
$ python3 p2.py ex1_test.py
00000000 66 72 6f 6d 20 65 78 31 20 69 6d 70 6f 72 74 20 |from ex1 import |
00000010 2a 0a 61 20 3d 20 30 62 31 31 30 31 30 31 30 31 |*.a = 0b11010101|
00000020 0a 70 72 28 61 29 0a 62 20 3d 20 7a 65 72 6f 5f |.pr(a).b = zero_|
00000030 6f 75 74 5f 74 6f 70 28 61 2c 20 33 29 0a 70 72 |out_top(a, 3).pr|
00000040 28 62 29 0a 63 20 3d 20 73 65 74 5f 6f 6e 65 5f |(b).c = set_one_|
00000050 61 74 28 61 2c 20 32 29 0a 70 72 28 63 29 0a 64 |at(a, 2).pr(c).d|
00000060 20 3d 20 73 65 74 5f 7a 65 72 6f 5f 61 74 28 61 | = set_zero_at(a|
00000070 2c 20 31 29 0a 70 72 28 64 29 0a 0a 0a |, 1).pr(d)...|
0000007d
bytes object.
str.isprintable() function to
determine if you should put '.' instead of the actual string.
See here.
end option in
print().
p3.py so that the following code works as follows.
|
Warning: No strings! No loops!The purpose of this part is learning how to manipulate bits. You are not allowed to use strings or loops in this part.You will get 0 point:
Other requirements
|
# p3_test.py
from p3 import *
a = 0b10110101
pr(a)
b = zero_out_top(a,3)
pr(b)
c = set_one_at(a, 4)
pr(c)
d = set_zero_at(c, 4)
pr(d)
~/bin/submit -c=IT430 -p=lab01 *.py lab01.docxNOTE: