Sure! Here's a Python program that asks the user for their name, age, and gender five times:
Python:
for i in range(5):
name = input("Enter your name: ")
age = input("Enter your age: ")
gender = input("Enter your gender: ")
print("Name:", name)
print("Age:", age)
print("Gender:", gender)
print()
print("Thank you for providing your information!")
In this program, a for loop is used to iterate five times. Inside the loop, input function is used to prompt the user for their name, age, and gender. The values entered by the user are stored in the variables name, age, and gender.
After collecting the information, the program prints the entered values using print statements. A blank line is printed using print() to separate the iterations.
Finally, the program prints a thank you message after the loop completes.
Sure! Here's a Python program that asks the user for their name, age, and gender five times:
Python:
for i in range(5):
name = input("Enter your name: ")
age = input("Enter your age: ")
gender = input("Enter your gender: ")
print("Name:", name)
print("Age:", age)
print("Gender:", gender)
print()
print("Thank you for providing your information!")
In this program, a for loop is used to iterate five times. Inside the loop, input function is used to prompt the user for their name, age, and gender. The values entered by the user are stored in the variables name, age, and gender.
After collecting the information, the program prints the entered values using print statements. A blank line is printed using print() to separate the iterations.
Finally, the program prints a thank you message after the loop completes.
Certainly! Here's an example of the same program that uses a while loop instead of a for loop:
Python:
i = 0
while i < 5:
name = input("Enter your name: ")
age = input("Enter your age: ")
gender = input("Enter your gender: ")
print("Name:", name)
print("Age:", age)
print("Gender:", gender)
print()
i += 1
print("Thank you for providing your information!")
In this version, we initialize the variable i to 0 before the while loop. The loop will continue as long as i is less than 5. Inside the loop, the program prompts the user for their name, age, and gender, and then prints the entered values. After that, we increment the value of i by 1 using i += 1 to ensure that the loop will eventually terminate after 5 iterations.
Once the loop finishes, the program prints the thank you message.