Programming Challenge - Up Down Counter

LAB: Up Down Counter

Challenge 1: - Up / Down Counter: Write a standalone Python program that will count from 0 to 25 and then back down to 0.  The output should print to the console the following:

Starting to count up
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25
Starting to count down
25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
Done

Before you run off to Google to find code that is already built to do this, please take some time to solve this on your own.  

Hint: - You will need a variable to hold the countValue.  I expect this program to use a while loop, and a few  If /else statements to test what the current value to the counterValue is.  You will need to test the counterValue to see when it should be counting up and when it should be counting down.

Challenge 2: - Add Some Complexity To Your Up Down Counter: You can add to this Up/Down Counter challenge by doing the following:
  • Trap a specific number while counting up and counting down
  • Trap when reach the number 15 when you are counting up.  Print something like:
   
Starting to count up
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
I see you have counted to 15
16,17,18,19,20,21,22,23,24,25
Starting to count down
25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
Done

  • Do the same thing, but with the number 17 when you are counting down.
   
    Starting to count down
25,24,23,22,21,20,19,18,
I see you are counting down and have counted down to the number 17
16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
Done

Challenge 3 - Add Input to Your Up Down Counter:  Add an input statement to your code, such that it will accept an integer input as a starting point for you counter. The output should print to the console the following:

Please input a starting value between 0 and 25
Starting to count up
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25
Starting to count down
25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
Done

Challenge 4 - Add Range Testing To Your Up Down Counter: Make the code more complex and robust.  When accepting user input, make sure they only enter a number from 0-25.  If they enter a  number smaller than 0 or larger than 25, trap that and tell them that only number from 0-15 are accepted and try again

Challenge 5 - Add Integer Testing To Your Up Down Counter: When accepting user input, make sure they only enter an integer.  If they enter a non-integer number, trap that, tell them that only number are acceptable, and to try again

Challenge 6 - Add A Way To Quit To Your Up Down Counter:  Provide them a way to quit.  They can enter a number from 0-25, or quit.  Test your code and see it you can still break it with odd input data...

No comments:

Post a Comment