Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 为什么帐户生成器和测验拼凑在一起会自我破坏_Python 2.7 - Fatal编程技术网

Python 2.7 为什么帐户生成器和测验拼凑在一起会自我破坏

Python 2.7 为什么帐户生成器和测验拼凑在一起会自我破坏,python-2.7,Python 2.7,输入y的用户名和密码有效吗?当我做测试时,它停止工作了吗? 我想这可能是测验的错误 这些代码单独工作 在写入之前,csv文件中没有任何内容 拼凑在一起时,为停止错误而进行的任何细微更改 python将生成一个新错误您的代码无效。我的意思是,语法无效-这不是Python运行时可以编译和执行的东西。这里有很多错误。行else print(“denied”):缩进不正确,也是一个语法错误。您在函数体之外有返回用户名。您有点==行[2],但尚未为点指定值。可能还有更多的错误。 import time i

输入y的用户名和密码有效吗?当我做测试时,它停止工作了吗? 我想这可能是测验的错误 这些代码单独工作 在写入之前,csv文件中没有任何内容 拼凑在一起时,为停止错误而进行的任何细微更改


python将生成一个新错误

您的代码无效。我的意思是,语法无效-这不是Python运行时可以编译和执行的东西。这里有很多错误。行
else print(“denied”):
缩进不正确,也是一个语法错误。您在函数体之外有
返回用户名
。您有
点==行[2]
,但尚未为
点指定值。可能还有更多的错误。
import time
import csv
import sys

print("Welcome...")
welcome = raw_input("Do you have an acount? y/n")
if welcome == "y":
        with open("user.csv",'r') as file:
            username=raw_input("Enter username")
            password=raw_input("Enter password")
            fileReader=csv.reader(file)
            for row in fileReader:
                if username==row[0] and password==row[1] and points==row[2]:
                    print("access granted")
                    return username
               else print("denied"):
                       login()


elif welcome == "n":
        username=raw_input("Enter username")
        password=raw_input("Enter password")
        with open("user.csv",'a') as file:
            csv_writer = csv.writer(file)
            csv_writer.writerow([username, password])
            print("access granted")
            return username
else:
    print("Ur stupid")
    sys.exit()




login()

import random
songsfile = open("songs.txt","r")
allsongs = songsfile.readlines() 

def quiz():
    tries = 2
    points = 0
    songnum = [1,3,5,7,9]
    print('An artist and the 1st letter of a song gets outputted')
    print('Get it wrong twice and game over...')
    print('1st guess = 3 points\n2nd guess = 1 point\n')
    while tries > 0:
        artist = random.choice(songnum)
        song = str(allsongs[artist - 1])
        print ('Artist: ' + allsongs[artist])
        print ('Song: ' + song[0])
        guess = raw_input('Input your guess: ')
        if guess.strip() == song.strip():
            print("Correct!")
            points += 3
        else:
            tries -= 1
            print('Incorrect')
            if tries > 0:

                guess = raw_input('Input your guess: ')
                if guess.strip() == song.strip():
                    print('Correct!')
                    points += 1
                else:
                    tries -= 1
                    print('Incorrect')
        print(points)
        time.sleep(3)
        if tries == 0:
            print(points)
            with open("user.csv",'a') as file:
                username=raw_input("Enter username")
                password=raw_input("Enter password")
                points=(points)
                csv_writer = csv.writer(file)
                csv_writer.writerow([username, password, points])
                print("game over")
                with open("user.csv",'r') as file:
                     print(file)



quiz()