Question

In: Computer Science

Chapter 8 Programming exercise 6 "Days of each month" Original Exercise: Design a program that displays...

Chapter 8 Programming exercise 6 "Days of each month"

Original Exercise:

Design a program that displays the number of days in each month. The program’s output should be similar to this:
January has 31 days.
February has 28 days.
March has 31 days.
April has 30 days.
May has 31 days.
June has 30 days.
July has 31 days.
August has 31 days.
September has 30 days.
October has 31 days.
November has 30 days.
December has 31 days.


The program should have two parallel arrays: a 12-element String array that is initialized with the names of the months, and a 12-element Integer array that is initialized with the number of days in each month. To produce the output specified, use a loop to step through the arrays getting the name of a month and the number of days in that month.

Modifications:

Use a single, two-dimensional array that has strings throughout.
Example array:
month_array = [ ["jan", "31"],
                              ["feb", "28"] ]

Using multiple lines to separate your data will make it easier to write the code without mistakes.

Use a while loop to iterate through the array and print the same output as shown above.

Turn IN:

No Raptor flowchart is required.

Thonny Python file (or Python file is written in any IDE/program)
        Turn in the actual Python code file "file_name.py"

Solutions

Expert Solution

Original code

#month array
month_array = ["January", "February", "March", "April", 
    "May", "June", "July", "August", "September", 
    "October", "November", "December"]

#days array with integer values specified number of days
days_array = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]


#simultaneously iterate both array ahnd prints an output
for (a, b) in zip(month_array, days_array): 
     print (a, "has", b, "days.") 

Please refer below screenshot of code to understand indentation of code and output.

Modification :

#month array
month_array = [["January", "31"],
    ["February", "28"],
    ["March", "31"],
    ["April", "30"],
    ["May", "31"],
    ["June", "30"],
    ["July", "31"],
    ["August", "31"],
    ["September", "30"],
    ["October", "31"],
    ["November", "30"],
    ["December", "31"]]
    
#to itearte 2 while loops to print desired output   
a = 0   
while a < (len(month_array)):
    b = 0
    while b < (len(month_array[a])-1):
        print (month_array[a][0], "has", month_array[a][1], "days.")
        b = b + 1
    a = a + 1

Please refer below screenshot of code to understand indentation of code and output.

Turn IN:

Save your above code in file_name.py(as per your wish whatever file name)


Related Solutions

Modified from Chapter 07 Programming Exercise 5 Original Exercise: Rock, Paper, Scissors Modification Programming Exercise 11...
Modified from Chapter 07 Programming Exercise 5 Original Exercise: Rock, Paper, Scissors Modification Programming Exercise 11 in Chapter 6 asked you to design a program that plays the Rock, Paper, Scissors game. In the program, the user enters one of the three strings—"rock", "paper", or "scissors"—at the keyboard. Add input validation (with a case-insensitive comparison) to make sure the user enters one of those strings only. Modifications: Allow the user to input "r", "p", "s" or the full strings "Rock",...
This is an exercise to design and write a Python program in good programming style for...
This is an exercise to design and write a Python program in good programming style for a simulation of stock price over a period of 100 days. In this exercise, you are asked to simulate the stock price starting at $100.00 for 100 days with a daily fluctuation based on the Normal Distribution with mean = 0.0 & sigma = 0.0125. The program will show the daily stock price, the 7-day minimum, the 7-day maximum, the 7-day average, and the...
C++ Programming: Programming Design and Data Structures Chapter 13 Ex 2 Redo Programming Exercise 1 by...
C++ Programming: Programming Design and Data Structures Chapter 13 Ex 2 Redo Programming Exercise 1 by overloading the operators as nonmembers of the class rectangleType. The header and implementation file from Exercise 1 have been provided. Write a test program that tests various operations on the class rectangleType. I need a main.cpp file Given: **************rectangleType.cpp******************** #include <iostream> #include <cassert> #include "rectangleType.h" using namespace std; void rectangleType::setDimension(double l, double w) { if (l >= 0) length = l; else length =...
Java Programming Write a program that displays the following pattern *                         *       &nbsp
Java Programming Write a program that displays the following pattern *                         *          *          * *          *          *          *          *          *          *          *          *          *          *          *             *          *          *          *          *                         *          *          *                                     * Printing Pattern A * ** *** **** ***** ****** ******* Printing Pattern B ******* ****** ***** **** *** ** * Printing Pattern C * ** *** **** ***** ****** *******
/** * Chapter 6 * Programming Challenge 1: Area Class * This program demonstrates the Area...
/** * Chapter 6 * Programming Challenge 1: Area Class * This program demonstrates the Area class. */ public class AreaDemo { public static void main(String[] args) { // Get the area of a circle with a radius of 20.0. System.out.println("The area of a circle with a " + "radius of 20.0 is " + Area.getArea(20.0)); // Get the area of a rectangle with a length of 10 // and a width of 20. System.out.println("The area of a rectangle with...
1. Chapter 5, Programming Challenge #8, Conversion Program (page 314). Program Name: FinalExamConversion. Write a program...
1. Chapter 5, Programming Challenge #8, Conversion Program (page 314). Program Name: FinalExamConversion. Write a program that asks the user to enter a distance in meters. The program will then present the following menu of selection: 1. Convert to Kilometers 2. Convert to Inches 3. Convert to Feet 4. Quit the Program The program will convert the distance to kilometers, inches or feet, depending on the user’s selection. Write the following methods: • getInput: This method prompts user to enter...
java programming question: "Write a program that displays a page on a topic of interest to...
java programming question: "Write a program that displays a page on a topic of interest to you (e.g., a sport, a city). Include at least one image and one shape (which can be text). " I wanted to do a soccer page but I don't know how to put pictures from the internet on Java. As for my object, I wanted to make a soccer ball. My professor has been really confusing in explaining graphics so any help is appreciated!
3. Complete programming project 5 in Chapter 5 of the Hanly/Koffman Problem Solving & Program Design...
3. Complete programming project 5 in Chapter 5 of the Hanly/Koffman Problem Solving & Program Design in C book. All input should be read from a file and output should be written to a file. Make sure that you design a function greatest_common_divisor() which calculates and returns the greatest common divisor of two integer numbers. Also, develop functions to read data from a file and to write data to a file. Problem Statement: The greatest common divisor (gcd) of two...
In this exercise, you will create a program that displays the amount of a cable bill....
In this exercise, you will create a program that displays the amount of a cable bill. The amount is based on the type of customer, as shown in Figure 10-30. For a residential cus- tomer, the user will need to enter the number of premium channels only. For a business customer, the user will need to enter the number of connections and the number of premium channels. Use a separate void function for each customer type. If necessary, create a...
In this exercise, you will create a program that displays the amount of a cable bill....
In this exercise, you will create a program that displays the amount of a cable bill. The amount is based on the type of customer shown in figure 10-30. For a residential customer, the user will need to enter the number of premium channels only. For a business customer, the user will need to enter the number of connections and the number of premium channels. Use a separate void function for each customer type. Enter your C++ instructions into the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT