You Will Complete This Assignment In Python 3.x. Make Sure Y ✓ Solved

You will complete this assignment in Python 3.x. Make sure yo

You will complete this assignment in Python 3.x. Make sure you have downloaded the software, and it is installed correctly. You will code the following and submit it in one file. Use the information in the Lessons area for this week to assist you.

Create a comment block (starts at line 1 in the code) with the following information:

""" Your name Course Name, Section (example: ENTD200 B002 Spr15) Instructor name Week # Date completed """

Problem 1: Create a list (or tuple only, no dictionary) that contains the months of the year. (do not hardcode the month number)

Problem 2: Create a loop to print the number and the months of the year from the list. The output should like this: Month 1 is January Month 2 is February …. …. Month 12 is December

Optional 1 (not required): Month 1 is January, ...Happy new year (Do not use if-then. Do not add the messages to the months list), create another list for greetings. The output will look like this Month 1 is January , ...Happy New Year! Month 2 is February, ...Happy Valentine! Month 3 is March Month 4 is April Month 5 is May Month 6 is June Month 7 is July, ...Happy Fourth of July! Month 8 is August Month 9 is September Month 10 is October, ...Happy Halloween! Month 11 is November, ...Happy Thanksgiving! Month 12 is December, ...Merry Christmas!

Optional 2: Modify the Payroll and/or the MPG program from week 5/6 to store the results in a list/dictionary. Print the list/dictionary when no more calculation is selected. The output will be something like this for the payroll: Payroll for week xyz James Bond ....... 21,500 Al Bundy ....... 500 Johnny English ….. 1,200 Total Payroll ....... 23,200. For the MPG will be something like MPG for zyz truck: Week 1 ..... 12 Week 2 ..... 33 Week 3 ..... 27 MPG Ave ..... 24

Paper For Above Instructions

In this assignment, we will explore basic programming concepts using Python 3.x, including list creation, loops, and output formatting. This exercise is designed to solidify understanding of lists and iterating over them for meaningful output. The tasks will cover creating a list or tuple of months, iterating over this structure to print out the name of each month along with its corresponding number, and incorporating optional greeting messages where applicable. Below is a breakdown of each problem outlined in the assignment.

Creating the List of Months

To start, we need to create a list that contains the months of the year. It’s important not to hardcode the month numbers; instead, we can simply utilize Python’s built-in capabilities to generate and access these values. We will also ensure that our code is properly documented within a comment block.

Your name

Course Name, Section (example: ENTD200 B002 Spr15)

Instructor name

Week #

Date completed

months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]

Looping Through the Months

The next task is to create a loop that will go through our list of months and print each month alongside its corresponding number. We will use a for loop that counts the index of each month and formats the output accordingly:

for index, month in enumerate(months, start=1):

print(f"Month {index} is {month}")

Optional Greetings

For enhanced output, we can add an optional list of greetings aligned with specific months. We will create a separate list for these greetings and use the month index to retrieve the right message for the appropriate month:

greetings = [

"Happy New Year!",

"Happy Valentine!",

"",

"",

"",

"",

"Happy Fourth of July!",

"",

"",

"Happy Halloween!",

"Happy Thanksgiving!",

"Merry Christmas!"

]

for index, month in enumerate(months, start=1):

message = greetings[index - 1] if greetings[index - 1] else ""

print(f"Month {index} is {month}{', ' + message if message else ''}")

Optional Enhancements for Payroll and MPG

The assignment also allows for optional enhancements including modifying previous programs, such as payroll or MPG calculations. The goal is to store results in dictionaries or lists and format the final output effectively. Here’s an example of what the payroll enhancement may look like:

payroll = {

"James Bond": 21500,

"Al Bundy": 500,

"Johnny English": 1200,

}

total_payroll = sum(payroll.values())

print(f"Total Payroll: {total_payroll}")

for employee, amount in payroll.items():

print(f"{employee} ....... {amount}")

Final Thoughts

This assignment covers fundamental Python techniques like list handling, looping, and data storage methods. By completing this exercise, one can gain confidence in using Python for both straightforward and slightly more complex programming tasks. Such practices form the cornerstone of programming fluency, essential for tackling bigger challenges in software development.

References

  • Python Software Foundation. (2023). Python Documentation. Retrieved from https://docs.python.org
  • W3Schools. (2023). Python Lists. Retrieved from https://www.w3schools.com/python/python_lists.asp
  • W3Schools. (2023). Python Loops. Retrieved from https://www.w3schools.com/python/python_for_loops.asp
  • GeeksforGeeks. (2023). Python Enumerate. Retrieved from https://www.geeksforgeeks.org/enumerate-in-python/
  • Real Python. (2023). Python Lists and List Comprehensions. Retrieved from https://realpython.com/python-lists-tuples/
  • Python.org. (2023). The Python Language Reference. Retrieved from https://python.org/
  • Programiz. (2023). Python Tuples. Retrieved from https://www.programiz.com/python-programming/tuple
  • Javatpoint. (2023). Python Comments. Retrieved from https://www.javatpoint.com/python-comments
  • Stack Overflow. (2023). Creating a List in Python. Retrieved from https://stackoverflow.com
  • Codecademy. (2023). Learn Python 3. Retrieved from https://www.codecademy.com/learn/learn-python-3