pythonloops

How do I print a specific number of input statements in a loop?


I'm writing a code for my class but I'm having a little trouble at one part. I'm having the user input a number and then I need a loop to print specific statements based off the number the user inputted. So for example:

def main():
    totalnumber = input("Enter the number of circles: ")
    i = 0
    for i in totalnumber:
        i = 0 + 1
        value = input("Enter the radius of circle",str(i)+":")

So I basically need the output to look like:

Enter the number of circles: 3
Enter the radius of circle 1:
Enter the radius of circle 2:
Enter the radius of circle 3:

I'm getting the error

TypeError: input expected at most 1 arguments, got 2

Is what I'm doing above okay to do or should I use a different approach? If its okay what is wrong within my code that would be giving me that sort of error?


Solution

  • Try:

    def main():
        total_number = input("Enter the number of circles: ")
        for number in range(1, int(total_number) + 1):
            value = input("Enter the radius of circle {}: ".format(number))
    
    main()
    

    First: you need to convert the input to int, then iterate it by the number.

    Notes: