Homework 2: Basic Python
Tasks
Seek help as soon as you are experiencing difficulty with this assignment.
Do not wait until the deadline to seek help!
Part 1 (2 points)
Create a simple Python program. Include your name and email in a comment at the top and indicate that this is homework #2. Import the math library. Place a blank line and a comment above each of the following parts. Save it as ABC12hw2.py, where ABC12 is your base Albion email address.
Part 2 (3 points)
Albion uses email addresses of the form [email protected] or sometimes just [email protected].
Write a Python print statement for each one of the five (or possibly four) characters in you email
so that each character is printed along with its decimal ordinal number, and the equivalent in binary and hexadecimal.
Use the ord()
, bin()
, and hex()
functions.
For example, if your email contained an x character, your code should print
x 120 0b1111000 0x78
Use either upper or lower case letters.
Part 3 (3 points)
Write a Python print statement that demonstrates \[e^{i \pi} = -1\] where \(i\) is the complex number representing \(\sqrt{-1}\).
Recall that Python uses j
to represent \(\sqrt{-1}\), so that the complex number
\(2 + 3i\) would be represented in Python as (2+3j)
.
Python's complex numbers are always of the form (x+yj)
where x
and y
are
integer or floating point numbers (sometimes zero).
Part 4 (3 points)
Fermat's little theorem states that \[2^{p-1} \mod p = 1\] for any prime \(p\). Write a Python print statement that demonstrates this for \(p = 341\). In other words, show \[2^{340} \mod 341 = 1.\]FYI, this type of calculation is done as a part of many data encryption algorithms that help secure internet traffic.
Recall that Python uses the %
operator for the mod operation.
Part 5 (3 points)
Write a Python print statement that demonstrates \[111,111,111 \times 111,111,111 = 12,345,678,987,654,321.\]
Part 6 (3 points)
Write a Python print statement that demonstrates \[\left(\frac{1000001}{1000000}\right)^{1000000} \approx e.\]
Part 7 (3 points)
Write a Python print statement that demonstrates \[569936821221962380720^3 + (−569936821113563493509)^3 + (−472715493453327032)^3 = 3.\]
It is unknown if every positive integer can be expressed as a sum of three integer cubes.
Deliverables
Send me ([email protected]) your Python .py
file as an attachment to an
email message with Homework 2 as the subject line.