1. Write a Python program named LastnameFirstname12.py, using your last name and your first name, that does the following:

  • Allow a user to create a database of information that can be saved to a file. The program can also retrieve and print the information that was saved to the file. In the Example Output, the program stores names and phone numbers. You can make your program store any information you want.
  • Create a save_data function. The dictionary of data and the user's preferred filename will be passed to this function. Write the key:value pairs to a text file in the form of a sentence.
    • For example, in the Example Output, the dictionary {'Nikki': '455-0123', 'Edward': '455-0987', 'Blanca': '455-3456'} is passed and the key:value pairs are written to the text file like this:
    Nikki's phone number is: 455-0123
    Edward's phone number is: 455-0987
    Blanca's phone number is: 455-3456
  • Create a retrieve_data function. The user's specified filename will be passed to this function. Print the contents of the file.
  • In the main function:
    • Create a dictionary that will hold the information that the user wants.
    • Print a greeting to the user and a menu of actions the user can input to:
      input data
      save data
      retrieve data
      end the program
    • Use a loop to continuously allow the user to enter an option until they exit the program.
    • If the user chooses to input data, allow them to enter 2 input and store the input as a key:value element in the dictionary
    • If the user chooses to save data, ask the user to specify a filename. Call the save_data function and pass it the dictionary and filename.
    • If the user chooses to retrieve data, ask the user to specify a filename. Call the retrieve_data function and pass it the filename.
    • If the user chooses to end the program, exit the loop and end the program.
  • Important: Make sure you always take into account the possibility that your user won't listen to instructions and may enter a command that doesn't exist. Remember to also take any measures needed to prevent your program from crashing. Test your code extensively.
  • All code in your program must be inside of a function definition, aside from import statements and calling main. Do not add more functions than specified here.
  • You may only call main once.

2. Be sure to add comments for each section of your code.

3. Your output must be descriptive. Make sure it's clear to the user what your program is doing.

Expected Output

>>>
Welcome to my phonebook program!

Press 1 to input phonebook data
Press 2 to save your data to a .txt file
Press 3 to retrieve data you've previously saved
Press 0 to exit

Enter a command: 1
Please enter a name: Nikki
Please enter a phone number: 455-0123

Enter a command: 1
Please enter a name: Edward
Please enter a phone number: 455-0987

Enter a command: 1
Please enter a name: Blanca
Please enter a phone number: 455-3456

Enter a command: 100
Invalid command. Please try again!

Enter a command: 2
Enter the filename to save your information in (for example: phonenumbers.txt)
my_phonebook.txt
All phone numbers have been saved to the file: my_phonebook.txt

Enter a command: 3
Enter the filename where your data is saved: my_phonebook.txt
Reading contents of file.....

Nikki's phone number is: 455-0123
Edward's phone number is: 455-0987
Blanca's phone number is: 455-3456

Enter a command: 1
Please enter a name: William
Please enter a phone number: 455-0000

Enter a command: 1
Please enter a name: Pete
Please enter a phone number: 455-9999

Enter a command: 2
Enter the filename to save your information in (for example: phonenumbers.txt)
my_phonebook.txt
All phone numbers have been saved to the file: my_phonebook.txt

Enter a command: 3
Enter the filename where your data is saved: my_phonebook.txt
Reading contents of file.....

Nikki's phone number is: 455-0123
Edward's phone number is: 455-0987
Blanca's phone number is: 455-3456
William's phone number is: 455-0000
Pete's phone number is: 455-9999

Enter a command: 0
Now exiting.....
>>>

Python Program 01A

0. Create a Python script named LastnameFirstname01A.py

1. This script will compute the circumference of a circle given a radius.

  • The formula for computing circumference is, that is 2 * PI * r.
  • For the value of PI, use the built-in PI constant in the math module.
    • Add the following import at the very top of the script: import math;
    • Calculating the circumference using the built-in PI constant will look like this: circumference = 2 * math.pi * radius;

2. Output a message stating to the user that this script calculates circumference.

3. Ask the user to enter in the radius.

4. Calculate the circumference.

  • If the user enters a radius less or equal to zero, make the circumference 0 instead of a negative number.

5. Output the result of the calculation.

6. All output is properly labeled.

7. It is okay when your program crashes if the user enters letters or symbols instead of a number, it should NOT crash if the user enters a decimal number or an integer.

8. Ensure that your code is sufficiently styled and documented.

Python Program 01A Example Output

> python MeyerEdward01A.py
Calculate the circumference of a circle given a radius.
Enter a radius: 3
~~~~~~~~~~~~~~~~~~~~
Circumference: 18.84955592153876

> python MeyerEdward01A.py
Calculate the circumference of a circle given a radius.
Enter a radius: 12.5
~~~~~~~~~~~~~~~~~~~~
Circumference: 78.53981633974483

> python MeyerEdward01A.py
Calculate the circumference of a circle given a radius.
Enter a radius: -0.0
~~~~~~~~~~~~~~~~~~~~
Circumference: 0

> python MeyerEdward01A.py
Calculate the circumference of a circle given a radius.
Enter a radius: -8
~~~~~~~~~~~~~~~~~~~~
Circumference: 0

Python Program 01B

0. Create a Python script named LastnameFirstname01B.py.

1. Note: This script has no user input.

2. Create a loop to print the numbers from 1 to 100, each number on its own line.

3. Modify the loop so that numbers with certain characteristics print a word instead:

  • For numbers divisible only by 3, print "Fizz" instead of the number.
  • For numbers divisible only by 5, print "Buzz" instead of the number.
  • For numbers divisible by 3 and 5, print "FizzBuzz" instead of the number.
  • All other numbers, just print them out.
  • Use the modulo operator % to determine if a number is divisible by another number.
    • For example, to test if a number is divisible by 3, the condition would be:
    • if (i % 3 == 0), where i represents the number you want to test which can be replaced by a value or another scalar variable that contains the number.

Python Program 01B Output

> python MeyerEdward01B.py
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.