需要项目作业方面的帮助

问题描述 投票:-1回答:1

我需要一些代码帮助,我对Python不太满意,所以我需要一些帮助,我写了一些看似合理的代码,但不断出现文件错误。请帮助我

我已经尝试过一些我认为会很好的代码,但一点都没有发现。它在Visual Studio中没有显示任何错误,但是每次我尝试运行它时,都会说“有些文件有错误,您是否仍要运行代码?”然后说“没有兼容的代码”。

以下是分配说明:请创建一个小程序以从附加数组中选择三个单词并显示这三个词以句子的形式呈现给用户。一个单词应该从中选择数组一,应选择一个单词数组二,应选择一个单词排列三个,然后以句子的形式向用户显示这些选择。“你的妈妈是勇敢的老虎烤。”这种侮辱是很奇怪的。提出另一个主题放在如果您不喜欢“您的妈妈”笑话,系统会选择三个字。如果要让用户选择一个数字并使用该数字来选择单词那就好了。如果您想使用随机函数来选择会没事的。该程序还需要询问用户是否要再次执行此操作,或者不。数组:

Description Words Mammals Action Words
Adorable Squirrel Apper
Adventurous Dog Feel
Accomplished Cat Get
Brave Pig Grow
Bright Goat Look
Composed Sheep Prove
Concerned Horse Remain
Demanding Bear Smell
Flustered Leopard Sound
Focused Tiger Stay
Gregarious Fox Taste
Grim Otter Turn
Handsome Meerkat Ask
Handy Giraffe Bake
Intelligent Monkey Build
Joyful Zebra Carry
Lanky Rhinoceros Help
Lazy Kangaroo Jump
Mellow Elephant Play
Miserable Seal Read
Items being tested:
Arrays
Looping
Print
Input or random
Syntax

这是我编写的代码:


    import random

    game = True
    YoMamastring = 'Your Mama is a'
    Description_Words = ['Adorable', 'Adventourus', 'Accomplished',
    'Brave', 'Bright', 'Composed', 'Concerned', 'Demanding',
    'Flustered', 'Focused', 'Gregarious', 'Grim', 'Handsome', 'Handy',
    'Intelligent', 'Joyful', 'Lanky', 'Lazy', 'Mellow', 'Miserable']
    Mammal_Words = ['Squirrel', 'Dog', 'Cat', 'Pig', 'Goat', 'Sheep',
    'Horse', 'Bear', 'Leopard', 'Tiger', 'Fox', 'Otter', 'Meerkat',
    'Giraffe', 'Monkey', 'Zebra', 'Rhinoceros', 'Kangaroo', 'Elephant',
    'Seal']
    Action_Words = ['Apper', 'Feel', 'Get', 'Grow', 'Look', 'Prove',
    'Remain', 'Smell', 'Sound', 'Stay', 'Taste', 'Turn', 'Ask', 'Bake',
    'Build', 'Carry', 'Help', 'Jump', 'Play', 'Read']
    Player_Choice = ("")
    Player_Choice2 = ("")
    Player_Choice3 = ("")
    while game == True:
     if Player_Choice == "Done":
       print(YoMamastring + {} + '' + {} + '' +
    {}.format(random.choice(Description_Words),
    random.choice(Mammal_Words), random.choice(Action_Words))
     elif Player_Choice in Description_Words:
     print("Choose your Words by typing them in as they are shown,No
    Quotations, if you want a random one, choose any key and press
    enter. If you want all your variables to be random, type 'Done', No
    Quotations.")
      print(Description_Words)
      Player_Choice = print('Choose your description word.\n')
      if Player_Choice in Description_Words:
           print(YoMamastring + {} + '' + {} + '' +
    {}).format(Player_Choice, Player_Choice2, Player_Choice3)
      else:
           Player_Choice = random.choice(Description_Words)
           print(YoMamastring + {} + '' + {} + '' +
    {}).format(Player_Choice, Player_Choice2, Player_Choice3)
      print(Mammal_Words)
      Player_Choice2 = print('Choose a Mammal Word.\n')
      if Player_Choice2 in Mammal_Words:
          print(YoMamastring + {} + '' + {} + '' +
    {}.format(Player_Choice, Player_Choice2, Player_Choice3)
      elif Player_Choice2 == random.choice(Mammal_Words)
           (YoMamastring + {} + '' + {} + '' + {}.format(Player_Choice,
     random.choice(Mammal_Words), Player_Choice3)
       print(Action_Words)
        c = print('Choose an Action Word.\n')
       if c in Action_Words:
          c = Player_choice3
          print(YoMamastring + {} + '' + {} + '' +
    {}.format(Player_Choice, Player_Choice2, Player_Choice3)
       else:
          c = random.choice(Action_Words)
           print(YoMamastring + {} + '' + {} + '' +
    {}.format(Player_Choice
    Player_Choice2, random.choice(Action_Words))
          print("Here is your Joke"")

如果可以的话,您能告诉我正确的方法并为我做完整的解释,我只是从Python开始,需要一些帮助。

python loops random input syntax
1个回答
0
投票

您的作业的简单版本可以按照以下步骤进行。

© www.soinside.com 2019 - 2024. All rights reserved.