我该如何用Python开发西班牙语动词变化研究工具?

2024-04-26 14:18:34 发布

您现在位置:Python中文网/ 问答频道 /正文

谢谢你花时间看我的帖子,我现在是一个西班牙语班的学生,我想做一个学习工具,让学生练习动词变化。在与代码学院的顾问交谈后,他推荐使用3级字典,你可以在我的代码中看到,我不熟悉这些字典,需要帮助!他简单地进行了随机分组,他的轮班结束了。以下是我在游戏中想要的主要内容

  1. 让程序随机选择一个动词、一个时态和一个冠词。

  2. 让程序请求用户输入并提出问题,例如,(动词)的(时态)(冠词)形式是什么?

例1:现在hacer的yo形式是什么?正确答案:哈戈

例2:现在hacer的tu形式是什么?正确答案:Haces

例3:什么是前礼形式的hacer?正确答案:Hice

  1. 让程序回复,说“正确!”或者“错了!”在

这是我现在的字典

import random  
verbs = {
'hacer': {
'present':{
    'yo': 'hago',
    'tu': 'haces',
    'elellausted': 'hace',
    'nosotros': 'hacemos',
    'ellosellasuds': 'hacen'
}
, 'preterite':{
    'yo': 'hice',
    'tu': 'hiciste',
    'elellausted': 'hizo',
    'nosotros': 'hicimos',
    'ellosellasuds': 'hicieron'
}
}
'tener': {
'present':{
    'yo': 'tengo',
    'tu': 'tienes',
    'elellaud':'tiene',
    'nosotros':'tenemos' ,
    'ellosellasuds':'tienen'
}
, 'preterite':{
    'yo': 'tuve',
    'tu': 'tuviste',
    'elellausted': 'tuvo',
    'nosotros': 'tuvimos',
    'ellosellasuds': 'tuvieron'
}
}
}

感谢所有能帮助我的人!我刚开始编程,但我已经做了大约6个月的网站设计。我愿意学习和任何帮助将不胜感激。在

如果你想建立某种类型的skype电话或聊天,这将是非常感谢,我将非常愿意!在

再次感谢您的阅读。在


Tags: 答案代码程序字典动词学生形式yo
1条回答
网友
1楼 · 发布于 2024-04-26 14:18:34

我有一些时间,所以这里有一些代码可以帮助你开始。它首先创建可能的冠词、动词和时态的列表(这些可以通过for循环找到,也可以由您手动输入)。然后它使用random模块从这些列表中随机选择一个条目。然后我们询问用户的答案,如果他们答对了,会给他们一个新的问题,并允许他们再试一次。 如果你有什么不明白的话就告诉我。在

import random  
verbs = {
'hacer': {
'present':{
    'yo': 'hago',
    'tu': 'haces',
    'elellausted': 'hace',
    'nosotros': 'hacemos',
    'ellosellasuds': 'hacen'
}
, 'preterite':{
    'yo': 'hice',
    'tu': 'hiciste',
    'elellausted': 'hizo',
    'nosotros': 'hicimos',
    'ellosellasuds': 'hicieron'
}
}, # ADDED A MISSING COMMA HERE
'tener': {
'present':{
    'yo': 'tengo',
    'tu': 'tienes',
    'elellaud':'tiene',
    'nosotros':'tenemos' ,
    'ellosellasuds':'tienen'
}
, 'preterite':{
    'yo': 'tuve',
    'tu': 'tuviste',
    'elellausted': 'tuvo',
    'nosotros': 'tuvimos',
    'ellosellasuds': 'tuvieron'
    }
    }
    }

article_list = ["yo", "tu", "elellausted", "nosotros", "ellosellasuds"]
verb_list = list(verbs.keys())

tense_list = []
for key in verbs:
  for tense in verbs[key]:
    if tense not in tense_list:
      tense_list.append(tense)
# or you could just manually type a list of tenses, probably more efficient. 

while True:
  article_choice = random.choice(article_list)
  verb_choice = random.choice(verb_list)
  tense_choice = random.choice(tense_list)

  question = "What is the {} {} form of {}?\n> ".format(tense_choice, article_choice, verb_choice)

  while True:
    response = input("{}".format(question)) #in python2: raw_input(..)

    if verbs[verb_choice][tense_choice][article_choice] == response.lower().strip():
      print("Correct!")
      break
    else:
      print("Incorrect, try again.")

相关问题 更多 >