Prompt the user for a number from 1 to 100 While that number is less than 1 or that number is more than 100 Output that they entered an invalid number Prompt them again for a number from 1 to 100 Output to the user, thanking them for their input

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Create a program called, MoreLoops, and add any necessary heading comments. Then write the code necessary in order to meet the criteria listed below for each loop. Again, you are creating one program with ALL of the loops inside. For debugging and testing, feel free to comment out loops that you know already work and use comments to label which loop you are working on. This goes a couple steps further than just outputting numbers - like you did in the lesson. Loops can be used for repetitive tasks or in input validation. Below are a few more loops you will need to create that involve a little more work. Additional guidance is provided (just follow the steps).

1. Prompt the user for a number from 1 to 100. Using a while loop, if they entered an invalid number, tell them the number entered is invalid and then prompt them again for a number from 1 to 100. If they enter a valid number - thank them for their input.

    • Prompt the user for a number from 1 to 100
    • While that number is less than 1 or that number is more than 100
      • Output that they entered an invalid number
      • Prompt them again for a number from 1 to 100
    • Output to the user, thanking them for their input

 

2. Prompt the user to guess your favorite color. Using a while loop, if the user didn't guess your favorite color [pick one for this activity] then tell them they are incorrect, then ask them again. Whenever they guess the color correctly, output that they are correct and how many guesses it took them.

    • Create a variable and assign it the value of 1
    • Prompt the user to guess your favorite color
    • While their guess is not equal to your favorite color
      • Tell them they are incorrect
      • Prompt them to guess again
      • Add one to the variable above
    • Output to the user, they were correct and how many attempts it took using the variable

 

3. Ask the user how many numbers for which they want to calculate the sum. Using a for loop, prompt the user to enter that many numbers, one-by-one, keeping track of the sum. At the end, after the user entered all numbers, output the sum.

    • Create a variable and assign it the value of 0
    • Prompt the user for how many numbers they have
    • With a for loop, set it to repeat enough times to get all their values
      • Prompt the user for a number
      • Add that number to the variable that started as 0
    • Output to the user, the sum of all values

USING PYTHON

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Graphical User Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education