【问题标题】:CS50 Final unsatisfied ConditionsCS50 最终未满足条件
【发布时间】:2022-10-05 00:18:04
【问题描述】:

我目前正在做我的 CS50 最终项目问题并且遇到了相当大的问题。下面是我的代码和每当我提供它时出现的错误消息。关于如何解决我不确定为什么会有很大帮助的问题的任何帮助。我的代码按预期工作,并且运行良好。但是,每当我尝试时,CS50 都无法正常工作。 (请忽略 README 错误,因为这只是长度问题)

我的主要问题是它没有检测到 3 个函数和 main 函数以及整个 py 的东西。

from termcolor import colored
import random

def main():
    run_game()
#I have the next couple of functions all put into effect in the run_game function. Therefore only need to do run game.


#This function takes a word to print, and an array containing the colours each letter should be printed input
#The first character in the word will be printed in the first colour in the array and so forth

def present_results(word, colours):
    if(len(word)==5 and len(colours) == 5):
        print(colored(word[0],colours[0]),
      colored(word[1],colours[1]),
      colored(word[2],colours[2]),
      colored(word[3],colours[3]),
      colored(word[4],colours[4]))
    else:
        print('Invalid input to present_results, word or array incorrect length, both should be length 5')
        print('[DEBUG] word length:',len(word),'colour array length:',len(colours))

#The following are tests for the present_results and randint functions

word = "PRINT"
colors = ['green','white','yellow','white','yellow']
#present_results(word, colors)




def generate_word ():
    words=['thorn','thick','light','might','cabin','paste','vocal','abode','right','urban','ghost',' zebra',
          'grail','tower','brave','crave','chase','image','night','print', 'shame','table','fable','diary','train', 'prick', 'stick', 'slice', 'solid',
          'space', 'other', 'about' , 'which', 'witch', 'faith', 'clown', 'scowel', 'towel', 'shelf' , 'stone', 'earth', 'extra', 'adieu', 'entry',
          'evict', 'clone', 'shady', 'stock', 'corks', 'actor']

#List of 50 words to pick from

    index=random.randint(0,49)
    return words[index]

#A lot of words thats returned to be the word that is guessed. its a list and using the random generator it is picked randomly and returned

def letter_in_word (string,letter):
    if letter in string:
        return True

    else:
        return False
#Straightforward, whether the letter is present in the word of not it returns true/false


def letter_in_place  (string,letter,index):
    if string[index]==letter:
        return True

    else:
        return False
#similiar to the top one, if it is in the correct or incorrect spot, it returns true/false



def guess_word (answer,guess):

    colors=[]
    for i in range(len(answer)):
        temp=letter_in_place(answer,guess[i],i)
        if temp==True:
            colors.append('green')

        elif temp==False:
            temp=letter_in_word(answer,guess[i])
            if temp==True:
                colors.append('yellow')

            elif temp==False:
                colors.append('white')

    return guess,answer,colors
#Basically colour cordinated function where in a loop if it follows the placement it is green, the letter is present it is yellow, and if none just white. Using the "in place" function and "letter in word" one too.

def run_game():
    answer=generate_word()
    for i in range(0,6):
        guess=input("Enter a guess: ")
        if guess==answer:
            print("Great Job,",answer, "is the right word!" )
            return
        guess,answer,colors=guess_word(answer,guess)
        present_results(guess,colors)

    print("All 6 Attempts Were Used, Try Again!")

#uses all the above functions and puts it all in one to simplify for the main function.


if __name__ == "__main__":
    main()

代码运行良好且符合预期,但是弹出的错误是:

:) README.md 存在 记录检查 README.md 是否存在...

:( 最终项目详情 原因 描述不够长。

:| project.py 存在 原因 直到皱眉头颠倒才能检查

:|主函数存在 原因 直到皱眉头颠倒才能检查

:|实现了除 main 之外的至少 3 个顶级函数 原因 直到皱眉头颠倒才能检查

【问题讨论】:

  • 我还应该补充一点,修复可能非常简单,我无法理解它。
  • 好吧,不知道can't check until a frown turns upside down 是什么意思,但也许这意味着它甚至没有检查,因为之前的测试没有通过。你可以告诉我们“忽略 README 错误,因为这只是一个长度问题”,但你能告诉自动评分员吗?另见can't check until a frown turns upside down

标签: python python-3.x cs50


【解决方案1】:

我很确定第二行 (Cause Description is not long enough.) 与您的代码无关,意味着 2 件事中的 1 件事:

  1. 您的README.MD 不够长,或者
  2. 您没有按照下面关于使用 Markdown 语法的说明进行操作如何提交.

    作为参考,我的项目 README 字数为 467,行数为 51。此外,这里是标记描述所需的 Markdown 语法。

    # YOUR PROJECT TITLE
    #### Video Demo:  <URL HERE>
    #### Description:
    TODO
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 2023-04-09
    • 2019-07-19
    相关资源
    最近更新 更多