我在底层编码课上,我必须创建一个程序,用户在其中输入整数。然后,该程序将运行一系列循环,以确定用户输入的序列的最小和最大值,以及用户输入的偶数和奇数的计数,同时还保持所有输入。输入的空白行告诉程序停止并输出先前声明的信息。正如问题所指出的,我不确定在程序进入循环并运行一个周期后如何解决该错误。这是到目前为止的代码:
counte=0
counto=0
sum=0
num=(input("Enter an integer (blank line to quit):"))
max=0
min=0
value=0
if(num==''):
print("No input values were provided.\nQuitting the program!!!")
while (num!=''):
value=int(input("Enter an integer (blank line to quit):"))
if(num%2==0):
counte+=1
else:
counto+=1
sum+=value
if(value>max):
max=value
if(value<min):
min=value
num=int(input("Enter an integer (blank line to quit:"))
print("The smallest value is",min, "and the larges value is",max,".")
print("The user entered",counte,"even, and",counto,"odd values.")
print("The cumulative total is",total,".")
运行该程序时遇到的语法错误如下所示:
Traceback (most recent call last):
File "*sensitive information*", line 12, in <module>
if(num%2==0):
TypeError: not all arguments converted during string formatting
答案 0 :(得分:0)
只需将其转换为实际整数:
num = int(input("Enter an integer (blank line to quit):"))