您可以一站式完成所有操作
how_many = int(input("How many terms are in the equation?"))
terms = {}
for i in range(how_many):
var = int(input("Enter the coefficient for variable"))
terms["T{}".format(i)] = var
然后您可以使用
print( terms['T0'] )
但是使用列表而不是字典可能更好
how_many = int(input("How many terms are in the equation?"))
terms = [] # empty list
for i in range(how_many):
var = int(input("Enter the coefficient for variable"))
terms.append(var)
然后您可以使用
print( terms[0] )
甚至(获得前三个学期)
print( terms[0:3] )