1 回答
TA贡献1830条经验 获得超9个赞
所以看起来你的问题由两部分组成。该ValueError产生是因为value = float("QUIT")被你的if语句中运行。但是它使它成为你的if语句摆在首位的原因是quit1缺少()在upper函数调用,也许需要输入。这样的事情应该工作:
def main():
print("Welcome to the matrix program!")
print("Enter the number of dimensions: ")
m = int(input("Enter number of rows: "))
n = int(input("Enter number of columns: "))
matrix = []
for i in range(m):
matrix.append([])
for j in range(n):
matrix[i].append(0)
print(matrix)
value = 0
quit1 = str("quit").upper()
while value != quit1:
row_loc = int(input("Enter a row location: "))
col_loc = int(input("Enter a column location: "))
value = input("Enter a value for the matrix of QUIT to stop: ")
if value.upper() != quit1:
value = float(value)
matrix[row_loc-1][col_loc-1] = value
else:
value = quit1
print(matrix)
choices = "What would you like to do? \n(1) APPLY \n(2) TRANSPOSE \n(3) PRINT \n(4) QUIT"
print(choices)
choice = int(input("Choice: "))
您还可以通过修改while语句中的相同内容并删除您的else
添加回答
举报
