Count Divisions
Write a function count(number)
, which counts the number of times that number can be divided by 10 before the result of the division is less than 1.
Example
Test Code | Output |
---|---|
print(count(-1)) | 0 |
print(count(0)) | 0 |
print(count(1)) | 1 |
print(count(2)) | 1 |
print(count(10)) | 2 |
print(count(15)) | 2 |
Reverse
Write the function reverse(text)
. The function should return the reverse of the characters in text.
Example
Test Code | Output |
---|---|
print(reverse(‘hello’)) | olleh |
print(reverse(‘radar’)) | radar |
Caesar
Most of us like to keep secrets. For example, I don’t want you to know my credit card number. I’d rather you not be able to buy things with my money. However, communication over the Internet is like trying to shout in a crowded room. Everyone can hear what you are saying. So, to protect our valuable secrets, we rely on encryption schemes. Today, you are going to implement a simplistic encryption scheme known since Roman times: Caesar cipher.
Encryption in the Caesar schema relies on shifting letters in the alphabet. By default, this shift is 3 letters. So, a becomes d, b becomes e, etc. The only issue with this is at the end of the alphabet. The end of the alphabet wraps around to the front. So, x becomes a, y becomes b, and z becomes c.
Details
Write two functions encrypt(text)
and decrypt(text)
that take a single string as a parameter. The encrypt
function should return the encryption of the text parameter using Ceasar cipher. The decrypt
function should return the decription of the text parameter using the Ceasar cipher.
Example
Test Code | Output |
---|---|
print(encrypt(‘hello’)) | khoor |
print(encrypt(‘goodbye’)) | jrrgebh |
print(decrypt(‘khoor’)) | hello |
print(decrypt(‘jrrgebh’)) | goodbye |
Hint
Submission
Please show your source code and run your programs for the instructor or lab assistant. Only programs that have perfect functionality will be accepted as complete.