Lööps Solved

25.00 $ 12.50 $



Problem: You are tasked with implementing a program that does a couple of things that will test your knowledge regarding while loops, for loops, and infinite loop conditions! The program will do all the following:


  1. Ask for an input that will be a positive, non-zero number in the range of [2, ∞). Indicate that, by entering -1, the user can exit the program. Ensure to have a check in place to determine if the input is -1, and to have a way to exit the program. If an entered number is out of range, indicate that it is invalid, and have the program start back from the beginning during runtime, meaning the program should not end and be run again.
  2. When exiting the program, print out the number of times the user has entered numbers. Again, it must NOT include the entering of the exit condition.
  3. Have a counter that keeps track of the number of times the user has entered a

number, not including the exit condition of -1. However, the counter WILL be keeping track of all other numbers, valid or invalid.

  1. If the entered number is valid, calculate and print the first five powers of that number. This must be implemented iteratively (i.e. through a for loop), and the use of the exponential math operator (**) is allowed.


All of that MUST be done within an infinite loop condition. In class, an infinite loop was demonstrated using a while loop. There are other ways of implementing an infinite loop condition as well, so do keep that in mind on approaching this assignment. Additionally, be mindful of edge test cases as well.



Sample Input/Output:


Example 1

Input: 0

Output: Invalid input!


Example 2

Input: 2






32                    Input: 1

Output: Invalid input!               Input: -1

Output: The user has entered 2 numbers!


Notes: Save your files as “firstname_lastname_loops.py”..