CS 100

Logo

Scientific Computing

Activity 20

Create a new python file called activity20.py and save to your cs100/ch4 folder.

  1. Write Python code that illustrates all the methods in Table 4.3 at page 137. You may use a dictionary created by yourself or the following one:
    cents = { 'Nickel': 5, 'Dime': 10, 'Quarter': 25, 'Dollar': 100}
    
  2. Use the dictionary below in a program that (a) asks the user to input a bonus, and then (b) adds the bonus to the salary of all employees in your dictionary, and then (c) prints out each person’s salary. (Hint: Use a for loop to update the salary.)
    personnel = {'Joe': 2000, 'Ana': 2500, 'Bob': 1800, 'Chris': 2100, 'Diana': 1900}
    
  3. Write Python code (no function need) to create a dictionary named userPasswords which holds 5 pairs of userName: password. Your program should allow for the user to input these pairs. Print the dictionary.

  4. Add code that asks the user to input their username. Your program will print their password, or “User not found” if the username doesn’t exist. This simulates that a user forgot their password.

If you finish early

  1. Add code that asks the user to input their username and then their password. Check if the passwords match.

  2. Challenging: Create a new dictionary called protectedUserPasswords which asks the user to type in 5 pairs of userName: password. This time, store the password as encrypted text rather than plain text. Next, add code so that the user can input their username/password and check for a match. Hint: think about how to match a password to an encrypted password.

How to submit

Submit your working activity20.py to Moodle.