Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is in Python. 6.11)Implement function easyCrypto() that takes as input a st

ID: 667178 • Letter: T

Question

This is in Python.

6.11)Implement function easyCrypto() that takes as input a string and prints its encryption
defined as follows: Every character at an odd position i in the alphabet will be
encrypted with the character at position i+1, and every character at an even position i
will be encrypted with the character at position i 1. In other words, ‘a’ is encrypted with
‘b’, ‘b’ with ‘a’, ‘c’ with ‘d’, ‘d’ with ‘c’, and so on. Lowercase characters should remain
lowercase, and uppercase characters should remain uppercase.
>>> easyCrypto('abc')
bad
>>> easyCrypto('Z00')
YPP

6.12)Write function letter2number() that takes as input a letter grade (A, B, C, D, F,
possibly with a - or +) and returns the corresponding number grade. The numeric values
for A, B, C, D, and F are 4, 3, 2, 1, 0. A + increases the number grade value by 0.3 and a -
decreases it by 0.3. (Do this using the dictionary method not multiway if)
>>> letter2number('A-')
3.7
>>> letter2number('B+')
3.3
>>> letter2number('D')
1.0

6.13)Define a dictionary called agencies that stores a mapping of acronyms CCC, FCC,
FDIC, SSB, WPA (the keys) to federal government agencies ‘Civilian Conservation Corps’,
‘Federal Communications Commission’, ‘Federal Deposit Insurance Corporation’, ‘Social
Security Board’, and ‘Works Progress Administration’ (the values) created by President
Roosevelt during the New Deal. Then:
(a) Add the map of acronym SEC to ‘Securities and Exchange Commission’.
(b) Change the value the value of key SSB to ‘Social Security Administration’.
(c) Remove the (key, value) pairs with keys CCC and WPA

6.14)Repeat above exercise with this change: Before making changes to agencies, define
acronyms to be the view of its keys. After making the changes, evaluate acronyms.

6.15)The dictionary used in Practice Problem 6.5 assumes that only one person can have
a certain first and last name. In a typical phone book, however, there can be more than one
person with the same first and last name. A modified dictionary that maps a (last name, first
name) tuple to a list of phone numbers could be used to implement a more realistic phone
book. Reimplement the lookup() function from Practice Problem 6.5 so it can take such
a dictionary (i.e., with list values) as input and return all the numbers that a (last name, first
name) tuple maps to.

This is practice problem 6.5:

def lookup(phonebook):

while True:

first = input('Enter the first name')

last = input('Enter the last name')

person = (first,last)

if person in phonebook:

print(phonebook[person])

else:

print('The name you entered is not known')

Explanation / Answer

6.11

def easycrypto(s):
    """
    :param s: (str)
    :return: Every character at an odd position i in the alphabet will be encrypted with the character at position
             i + 1, and every character at an even position i will be encrypted with the character at position i - 1.
    """
    alpha = 'abcdefghijklmnopqrstuvwxyz'
    alpha2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    alpha3 = alpha + alpha2
    al3 = list(alpha3)

    ad = {}
    nd = {}
    count = 0
    for letter in al3:
        count += 1
        ad[letter] = count
    count = 0
    for letter in al3:
        count += 1
        nd[count] = letter
    sl = list(s)
    for i in range(len(sl)):
        if sl[i] in al3:
            ch = sl[i]
            num = ad[ch]
            if num % 2 == 0:
                sl[i] = nd[num - 1]
            else:
                sl[i] = nd[num + 1]
    return ''.join(sl)


print(easycrypto('abc'))
print(easycrypto('ZOO'))

6.12

def letter2number(s):
    """ Takes a letter grade (A, B, C, D, F, with + or -) and returns corresponding number grade. The numeric values
        for A, B, C, D, and F are 4, 3, 2, 1, 0, a + increases number grade value by 0.3 and a - decreases it by 0.3
    """
    grades = {'A': 4,
              'A-': 3.7,
              'B+': 3.3,
              'B': 3.0,
              'B-': 2.7,
              'C+': 2.3,
              'C': 2.0,
              'C-': 1.7,
              'D': 1.0,
              'F': 0}
    if s in grades:
        return grades[s]
    else:
        return 0


print(letter2number('A'))
print(letter2number('B+'))
print(letter2number('F'))

6.13
agencies = {'CCC': 'Civilian Conservation Corps',
            'FCC': 'Federal Communications Board',
            'FDIC': 'Federal Deposit Insurance Corporation',
            'SSB': 'Social Security Board',
            'WPA': 'Works Progress Administration'}
print(agencies)
acronyms = agencies.keys()
print(acronyms)
# A
agencies['SEC'] = 'Securities and Exchange Commission'
print(agencies)
# B
agencies['SSB'] = 'Social Security Administration'
print(agencies)
# C
agencies.pop('CCC')
agencies.pop('WPA')
print(agencies)

6.14
print(acronyms)


6.15
phonebook5 = {('Anna', 'Karenina'): ['(123)456-78-90', '(777)777-77-77'],
              ('Yu', 'Tsun'): '(901)234-56-78',
              ('Hans', 'Castorp'): '(321)908-76-54'}
print(phonebook5)


#print(lookup(phonebook5))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote