# Python program to count the number of times the user enters the integer ‘2’ (using while loop and for loop)

Here is the code for the python program to count the number of times the user enters the integer ‘2’ (using while loop and for loop). First, the problem is solved is using for loop and then while loop.

```
# Implement a program that prompts the user to enter 10 integers (there can be repetition). The
# program will count the number of times the user enters the integer ‘2’. The count will be
# displayed on the output screen. Implement using both while and for loops

# Using while loop
user_input_count = 1
two_count = 0
while user_input_count <= 10:
user_input = int(input('Enter the number: '))
if user_input == 2:
two_count +=1
user_input_count += 1
print("You entered the integer '2',", two_count, "times.")

#Usind for loop
user_input_count = 1
two_count = 0

for i in range(10):
user_input = int(input('Enter the number: '))
if user_input == 2:
two_count += 1
print("You entered the integer '2',", two_count, "times.")user_input_count = 1
two_count = 0

# This code is contributed by Ahmad Shafiq
``` ## Love this read? Subscribe to Modernage!

Do you have any queries? You can ask in the comments. We, at Modernage answer each and every question, asked in the comments, so If you have any queries, or you want to know about any specific platform you can ask in the comments below

## Author

### This Post Has 3 Comments

1. Faisal

It’s Working.
Thank you

1. 2. Amy

Hi,

I need a program that does the following:

20 students select their month of birth as an integer (1-12). Students with months 1-4 get assigned to group X, from 5-8 assigned to group Y and from 9-12 to group Z. It must also count how many students are in each group after all 20 register. Please help. ## More Articles.  ### Python program to find the factorial of a number using while loop and for loop.

Here is code for python program to find the factorial of a number using while loop and for loop.  ### Python program that reads three nonzero integer values and determines and prints whether they could represent the sides of a triangle.

Here is code for a python program that reads three nonzero integer values and determines and prints whether they could represent the sides of a  ### Python program to take two integers from the user and determine and print whether the first is a multiple of the second.

Here is the code for the python program to take two integers from the user and determine and print whether the first is a multiple

## Python

### Python program to print star patterns in python ## More Articles.  ### What is WEB3? Why is it important! (Simply Explained)

Famously known as web 3.0, web3 is an era  ### Online Shopping in Pakistan: Ultimate Guide (Jan. 2022)

The concept of online shopping has revolutionized the way  