How to Create A Python Counting Program

python counting program


How to create a python counting program

This is a Python 3 tutorial for creating a counting program, and in order to get started I always start with a comment about what the program should entail. By using the # key, you can then create comments in Python.

# this is a simple while program that counts


number = int(input("Please provide a number between 1 and 100 that I can count to: "))

x = 1
 
if number >= x and number <= 100:

              while number >= x and number <= 100:
                             print(x)
                             x = x+1
              print("Thank You! I enjoyed counting to the number", number)


else:
              print("Sorry I can't count to that!")

The code below is slightly similar to the code above but with slight differences.


# this is a simple while program that counts

              number = int(input("Please provide a number between 1 and 100 that I can count to: \n "))

if number > 100 or number < 1:
              print("sorry I cant count to that!")          
              
else:
              x = 1

              while number >= x and number <= 100:
                             print(x)
                             x = x+1
              print("\nThank You! I enjoyed counting to the number", number)


These are two slightly different codes for counting in python. Remember when coding in python indentation is very important when copying this code, you may want to ensure that the methods line up such as the if/else statements, and the loops such as while and for.  

 




Check out the newest version of the python overtime program! - https://youtu.be/YQd7Owrc6vg
Check Out More Python Programs!
Python While Loop Hourly Wage - https://youtu.be/XBb6UxhLjq4
Python Multiple Inputs - https://youtu.be/GXo58Bmd6rk
Python Math Game - https://youtu.be/cbGBwqVA5YA
Python Guessing Game - https://youtu.be/LMuyEOhn6V0
Python While Loops - https://youtu.be/KePl1jhLg3A
Python Functions - https://youtu.be/4y4XgFjkLvk
Python Wage Calculator - https://youtu.be/xPSskCnKhGE
Python Celsius Converter - https://youtu.be/wbdUd6v_thY
Python Pay Program - https://youtu.be/iAoPMkSwySU
Python Input Program - https://youtu.be/sf8EPvt3dJI


As always, check out my youtube channel for more java for beginners videos. If you have any recommendations on new content or if there are areas that could be more helpful for you in learning java, please leave a comment for me here or on my youtube channel. I will consider your recommendation and may make a video primarily related to any video requests you may have to help increase your knowledge of the matter.

Remember to subscribe to get new content as soon as it is available with my link below.


No comments:

Post a Comment

Flag Quiz Game

Enjoy this free android app in the google play store. If you want to learn about the many country fl...