Question: Introduction In this project we use a while loop to print parts ofa well-known nursery rhyme. Humpty Dumpty sat on a wall, Humpty Dumpty had

Introduction

In this project we use a while loop to print parts ofa well-known nursery rhyme.

Humpty Dumpty sat on a wall,
Humpty Dumpty had a great fall.
All the king's horses and all the king's men
Couldn't put Humpty together again.

Specifications

  1. Write a program with a single while-loop that printsnumbers from 1 to an upper limit, each on their own line, butsubstituting parts of the rhyme for certain numbers as specifiedbelow.
  2. Ask the user for a single maximum count number, and no otherinput, prompting the user with these words: Enter max:
  3. When the loop count reaches a multiple of five print"Humpty" instead of the number.

    Hint: put if-statements inside the braces of theloop.

  4. When the loop count reaches a multiple of seven print "Dumpty"instead of the number.
  5. For numbers which are multiples of bothfive and seven print "Had a Great Fall"instead of the number.
  6. Add a file comment block at the top of the code with a projectdescription, your name, pair-partner's name, and datecompleted.
  7. As with all projects, only use techniques we have covered sofar in the course and meet all academic integrity requirements ofthe syllabus.

Example: If the input is:

35

the output in a console or terminal is:

Enter max: 351234Humpty6Dumpty89Humpty111213DumptyHumpty16171819HumptyDumpty222324Humpty2627Dumpty29Humpty31323334Had a great fall

where the user enters the values shownin bold-italics (for emphasis)to produce the output. User input only appears if entered in aconsole or terminal and does NOT showin bold-italics.

Hints:

  • Put several if-else statements inside the braces ofthe single for-loop.
  • Test for numbers that are multiples of both7 and 5 first.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!