Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Elementary Statistics

Authors: Mario F. Triola

12th Edition

0321836960, 978-0321836960

Students also viewed these Programming questions

Question

Define the expected rate of return to bondholders.

Answered: 1 week ago