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

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 =...
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...
C++ PROGRAM Programming Exercise 11 in Chapter 8explains how to add large integers using arrays. However,...
C++ PROGRAM Programming Exercise 11 in Chapter 8explains how to add large integers using arrays. However, in that exercise, the program could add only integers of, at most, 20 digits. This chapter explains how to work with dynamic integers. Design a class named largeIntegers such that an object of this class can store an integer of any number of digits. Add operations to add, subtract, multiply, and compare integers stored in two objects. Also add constructors to properly initialize objects...
write a program that computes and displays the number of days that have elapsed between January...
write a program that computes and displays the number of days that have elapsed between January 1, 1900 and today (the day the program is run). The program must be designed as follows: Within a class named Elapsed_Days, provide the following functions: • bool is_year_valid(long year) returns true if year is >= 1900; otherwise false • bool is_month_valid(long month) returns true if month is between 1 and 12 (inclusive); otherwise false • bool is_leap_year(long year) returns true if year is...
Intro C++ Programming Chapter 6 Functions You have been tasked to write a new program for...
Intro C++ Programming Chapter 6 Functions You have been tasked to write a new program for the Research Center's shipping department. The shipping charges for the center are as follows: Weight of Package (in kilograms)                Rate per mile Shipped 2 kg or less                                                      $0.05 Over 2 kg but no more than 6 kg    $0.09 Over 6 kg but not more than 10 kg    $0.12 Over 10 kg    $0.20 Write a function in a program that asks for...
Design a program that displays the following in Java: Enter the grades for an Essay: Grammer...
Design a program that displays the following in Java: Enter the grades for an Essay: Grammer (must be 30 or less): 40 Grammer (must be 30 or less): 26.3 Spelling (must be 20 or less): 17.4 Correct Length (must be 20 or less): 19 Content (must be 30 or less): 23.5 The recorded scores are: Grammer: 26.3 Spelling: 17.4 Correct Length: 19.0 Content: 23.5 Total score: 86.2 The grade for this essay is B
Design the logic for a program that allows a user to enter 20 numbers, then displays...
Design the logic for a program that allows a user to enter 20 numbers, then displays them in the reverse order of entry. Design the logic for a program that allows a user to enter 20 numbers, then displays each number and its difference from the numeric average of the numbers entered. The program is C++. I need a Pseudocode
DESIGN A FLOWCHART IN THE APPLICATION FLOWGORITHM Exercise called: Number Analysis Program Design a program that...
DESIGN A FLOWCHART IN THE APPLICATION FLOWGORITHM Exercise called: Number Analysis Program Design a program that asks the user to enter a maximum of 20 numbers. The program should store the numbers in an array and then display the following data: 1-The lowest number in the array. 2-The highest number in the array. 3-The total of the numbers in the array. 4-The average of the numbers in the array. PLEASE AND THANK YOU
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT