问题描述:

my code (shown below) keep returning the programmed in errors, for example, if I enter 0, it stills states the answer is invalid, I know there is something I'm overlooking, any help would be appreciated!

(sorry if it's really simple and I just hadn't noticed, it's my first time coding)

 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)

When you print a value, it is not assigned to the variable. Just fix that and it works.

相关阅读:
Top