[英]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?
如果它在我的代码中有什么问题可以给我那种错误呢?
Your for loop doesn't look correct. 你的for循环看起来不正确。 Try
尝试
for number in range(int(totalnumber)):
i = number+1
value = input("Enter the radius of circle"+str(i)+":")
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. 首先:您需要将输入转换为
int
,然后按数字迭代。
Notes: 笔记:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.