你好,我是悦创。

5.3 remove word(words: tuple[str, ...], word: str) -> tuple[str, ...]

Returns a copy of words with word removed, assuming that words contains word exactly once.

# 作业基本要求
def remove_word(t_words, word) -> tuple:lst = list(t_words)
#     i = lst.index(word)lst.remove(word)return tuple(lst)
words = ("Python", "apples", "candle")
new_words = remove_word(words, "candle")
print(words)
print(new_words)

扩展:

def remove_word(t_words, word) -> tuple:if word in t_words:lst = list(t_words)lst.remove(word)return tuple(lst)else:return t_words
words = ("Python", "apples", "candle")
new_words = remove_word(words, "aiyc")
print(words)
print(new_words)

5.4 prompt user(guess number: int, words: tuple[str, ...]) -> str

Prompts the user for the next guess, reprompting until either a valid guess is entered, or a selection for help, keyboard, or quit is made. Returns the first valid guess or request for help, keyboard, or quit. Note that the processing of the guess once it has been entered does not need to be handled in this function; it will be handled in functions defined later in this section. The returned string must be lowercase.

这个意思就是从 vocab.txt 的范围猜词,然后必须是猜的词必须是六个字母,如果填了不在 vocab.txt 里的词就会识别不出来。

5.4.1 Example usage

def load_words(filename: str) -> tuple[str,...]:""" Loads all words from the file with the given name.Parameters:filename (str): The name of the file to load from. Each word must be ona separate line.Returns:tuple<str>: A tuple containing all the words in the file."""with open(filename, 'r') as file:words = [line.strip() for line in file.readlines()]return tuple(words)def prompt_user(number, content):i = 1while i <= number:guess_text = input("Enter guess " + str(number) + ":")# print(i) # 判断 while 循环次数if len(guess_text) < 6:print("Invalid! Guess must be of length 6")elif guess_text in content:breakelse:print("Invalid! Unknown word")i += 1return guess_textvocab = load_words("data/vocab.txt")
# print(vocab)
guess = prompt_user(4, vocab)
print(guess)
def load_words(filename: str) -> tuple[str,...]:""" Loads all words from the file with the given name.Parameters:filename (str): The name of the file to load from. Each word must be ona separate line.Returns:tuple<str>: A tuple containing all the words in the file."""with open(filename, 'r') as file:words = [line.strip() for line in file.readlines()]return tuple(words)def prompt_user(number, content):i = 1while i <= number:guess_text = input("Enter guess " + str(number) + ":")# print(i) # 判断 while 循环次数if len(guess_text) < 6:print("Invalid! Guess must be of length 6")elif guess_text not in content:print("Invalid! Unknown word")else:breaki += 1return guess_textvocab = load_words("data/vocab.txt")
# print(vocab)
guess = prompt_user(4, vocab)
print(guess)

5.5 process guess(guess: str, answer: str) -> str

Returns a modified representation of guess, in which each letter is replaced by:

  • A green square if that letter occurs in the same position in answer;
  • A yellow square if that letter occurs in a different position in answer; or
  • A black square if that letter does not occur in answer.

While answers must contain 6 unique letters, guesses may contain duplicate letters. If duplicate letters exist in the guess, only one can have a non-black square. If the letter doesn’t exist in the answer, all occurrences of said letter in guess are given black squares. If the letter does exist in answer, the non-black square is allocated as follows:

  1. If one of the occurrences is in the correct position, it receives a green square and all other occurrences receive a black square.

  2. Otherwise, if no occurrences are in the correct position, the first occurrence of the letter in guess receives a yellow square and all other occurrences receive a black square.

Precondition: len(guess) == 6 and len(answer) == 6
See a1 support.py for constants containing the required square characters.

意思是如果 guess 的字母跟 answer 的相同并且位置相同,那就显示成绿色方块,如果字母相同位置不同,显示成黄色方块,都不是显示黑色方块,如果 guess 里面有两个跟 answer 其中一个字母相同,只能有一个是黄色方块,另一个是黑色方块。

5.5.1 Example usage


如果 guess 里面有两个字母跟 answer 里面其中一个相同,guess 中有一个正好是在相同位置, 另一个的字母被排除掉变成黑色方块。

CORRECT = "												

Python私教学员作业「一对一教学」相关推荐

  1. Python私教/Java私教「一对一教学」

    你好,我是悦创. 计算机行业10年经,不同于千篇一律的教育机构,我的教育模式直面新人成长学习痛点,采用师徒模式,在课程讲授过程中,我会亲自一对一帮扶讲解,把我多年积累的经验和良好的代码素养传递给新人, ...

  2. Vue3 Typescript + Axios 全栈开发教程:手把手教你写「待办清单」APP

    本文完整版:<Vue3 Typescript + Axios 全栈开发教程:手把手教你写「待办清单」APP> Vue3 Typescript + Axios 全栈开发教程 前端 Vue3 ...

  3. TML5期末大作业:女性化妆品商城网站设计——女性化妆品商城(3页) HTML CSS 网页设计作业「商城小站」

    HTML5期末大作业:女性化妆品商城网站设计--女性化妆品商城(3页) HTML CSS 网页设计作业「商城小站」 常见网页设计作业题材有 个人. 美食. 公司. 学校. 旅游. 电商. 宠物. 电器 ...

  4. python 彩票自动下单,从「获取数据」到「自动下单」 | 《Python量化投资入门》培训...

    原标题:从「获取数据」到「自动下单」 | <Python量化投资入门>培训 2015年年底的时候,我在学Python,中间一些问题总是搞不明白,在网上搜资料的时发现了一篇非常好的教程--& ...

  5. python羊车门问题_「羊车门」经典概率题中不换门选中车的概率是多少?

    今天用Python求解「羊车门」经典的概率问题,对概率学基础和Python语法的灵活运用有所收货. 本次「羊车门」求解过程采用的是:穷举法计算概率已验证概率学基础理论.期间重点借鉴了'奥卡姆剃刀的博客 ...

  6. 史上最强攻略!手把手教你建「数据中台」!

    文章转自「首席数字官」 ID:ChiefDigitalOfficer 作者:李国欢 4 月 24 日晚,由数澜科技联合锦囊专家共同打造的<数据中台硬核汇>系列线上微课第一讲火热开启.100 ...

  7. DeepMind新语言模型SUNDAE:教自动编码器学会「自我纠正」,WMT14英德互译任务获SOTA...

    丰色 发自 凹非寺 量子位 报道 | 公众号 QbitAI 一直以来,自回归语言模型(Autoregressive model,AR)在文本生成任务中表现都相当出色. 现在,DeepMind通过教自动 ...

  8. python创建工作簿_「总结篇」Python中所有的Excel操作技巧

    Python对于Excel的操作是多种多样的,掌握了相关用法就可以随心所欲的操作数据了! 操作xls文件 xlrd(读操作): import xlrd 1.引入xlrd模块 workbook=xlrd ...

  9. 用python爬取网站_「自如网」关于用python爬取自如网信息的价格问题(已解决) - seo实验室...

    自如网 ###这是一篇求助文,我能获取图片并变成字符串,但是无法获取位移量### 前两坛突发奇想想要爬取自如网的租房数据,本来以为能够请求+美丽+ re能全部搞定,没想到这个网站的反爬机制有点让我搞不 ...

最新文章

  1. Linux初学(Linux命令行的使用)
  2. POCO:InvalidOperationError:Mapping and metadata information could not be found for Entity Type
  3. netty服务器定时发送消息,netty+websocket+quartz实现消息定时推送
  4. 查询各个分区的数据量_分库、分表、分区的区别,傻傻分不清?
  5. IntelliJ IDEA for Mac的快速切换当前主题方案(Quick switch current scheme)
  6. Elasticsearch安装X-Pack插件
  7. 带父节点的平衡二叉树_Python算法系列—深度优先遍历算法【二叉树】
  8. Jmeter使用方法
  9. apache jmeter 使用
  10. 网页长截图工具_Mac系统如何轻松实现网页长截图功能
  11. win10下如何安装.NetFrame3.5框架
  12. 编译原理 编译器自动生成工具
  13. div+css实现盖章
  14. KGB知识图谱能够为公司分析上市影响因素
  15. Java_实现身份证信息提取个人信息
  16. matlab复化梯形公式误差,数值分析复化梯形公式,复化Simpson公式MATLAB程序
  17. (二)移动 GPU 和桌面 GPU 的差距有哪些?
  18. 3种Flink State Backed| 你该用哪个?
  19. 2014年禁毒工作总结,2015年工作打算
  20. css写阴影颜色渐变,css3——阴影(立体感,层次效果),渐变色按钮

热门文章

  1. 机器学习实战:K-近邻(KNN)算法识别26个大写英文字母(A到Z)(含拍照检验步骤详解)
  2. html超链接怎么换行,富文本过程中我遇到的问题以及解决方法(超链接换行以及无法接收超链接鼠标事件以及br或者nbsp;标签会崩溃报错的问题)...
  3. 为什么阿谀奉承之辈能在公司横行这么久?
  4. mysql删除大表更快的drop table办法(转老金)
  5. 基于区块链技术的智能网联汽车数据跨境安全研究
  6. PowerMill 2017五轴联动编程视频教程
  7. Codeforces Round #666 (Div. 2)E Monster Invaders
  8. 示波器测量晶振、万用表测量晶振的方法
  9. Oracle数据恢复顾问(DRA)
  10. 强化学习:DDPG到MADDPG