[英]Python error when reading from csv file and accepting input from user
我的代码(如下所示)不断返回错误的编程代码,例如,如果我输入0,它仍然显示答案无效,我知道我在忽略某些东西,我们将不胜感激! (对不起,如果真的很简单,我只是没有注意到,那是我第一次编码)
with open ("Lineup.csv", "rt") as fileopen:
file = csv.reader(fileopen, delimiter=',')
array = []
score = 0
for row in file:
array.append(row)
for i in array:
like = ""
likeness = ""
print(i)
like = print(input("If 1 is yes and 0 is no, do you like/know this band?"))
if like == "0":
score + 0
like = ""
if like == 1:
print(i)
like = 0
likeness = print(int(input("If 1 is worst and 3 is best, how much do you like them?")))
if likeness == 1:
score + 1
likeness = 0
if likeness == 2:
score + 2
likeness = 0
if likeness == 3:
score + 3
likeness = 0
else:
print(i)
likeness = print(int(input("Answer was not valid, please choose a number from 1-3, how much do you like this band?")))
else:
print(i)
like = print(input("Answer was not valid, please choose 0 or 1, do you like this band?"))
file.close
with open ("Lineup.csv", "rt") as fileopen:
file = csv.reader(fileopen, delimiter=',')
array = []
score = 0
for row in file:
array.append(row)
for i in array:
like = ""
likeness = ""
print(i)
like =input("If 1 is yes and 0 is no, do you like/know this band?")
print like
if like == "0":
score + 0
like = ""
if like == 1:
print(i)
like = 0
likeness = int(input("If 1 is worst and 3 is best, how much do you like them?"))
print likeness
if likeness == 1:
score + 1
likeness = 0
if likeness == 2:
score + 2
likeness = 0
if likeness == 3:
score + 3
likeness = 0
else:
print(i)
likeness = print(int(input("Answer was not valid, please choose a number from 1-3, how much do you like this band?")))
else:
print(i)
当您打印值时,不会将其分配给变量。 只需修复它,它就可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.