- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尽管这个填空脚本成功运行,但我不确定如何随机分配空白。可以看到,我在 5-7 之间放置了两个空格。但是,我想随机化它们的设置位置。
sentence = """Immigration is an issue that affects all residents of the United States, regardless of citizenship status"""
sentence0 = sentence.split(" ")
max = len(sentence)
sentence1 = sentence0[0:5]
sentence1 = " ".join(sentence1)
sentence2 = sentence0[7:max]
sentence2 = " ".join(sentence2)
Overall = sentence1 + " _ _ " + sentence2
print(Overall)
test = input()
Overall2 = sentence1 + " " + test + " " + sentence2
print(Overall2)
start = "\033[1m"
end = "\033[0;0m"
if Overall2 == sentence:
print(start + "Correct" + end)
else:
print(start + "Incorrect" + end)
最佳答案
这很简单并且有效:
import random
sentence = "Immigration is an issue that affects all residents of the United States, regardless of citizenship status"
words = sentence.split(" ")
#SELECT RANDOM WORD FOR PLACING BLANK
rand_index = random.randint(0, len(words)-1)
#KEEP A BACKUP OF THE WORD
word_blanked = words[rand_index]
#REPLACE WORD WITH BLANK
words[rand_index] = "_____"
#MAKE BLANKED SENTENCE AND CORRECT ANSWER
blanked_sentence = ""
correct_answer = ""
for word in words:
blanked_sentence = blanked_sentence + word + " "
if word == "_____":
correct_answer = correct_answer + word_blanked + " "
else:
correct_answer = correct_answer + word + " "
print(blanked_sentence)
answer = input("Enter your answer : ")
if answer == word_blanked:
print("Correct Answer!")
else:
print("Wrong Answer!")
print("Correct Answer is : ")
print(correct_answer)
关于python - 随机填空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65567240/
我在替换字符串时遇到问题。 这是 Question 类方法。 public class Question { private String text; private String answer; /
我已尝试找到执行此操作的方法并在此处在线搜索,但找不到可帮助我解决此问题的示例。 我正在读取大型 csv 中的行并将每一行更改为列表。问题是数据源不是很干净。有时它有空字符串或错误数据,发生这种情况时
我正在制作一个小文字游戏,其中缺少一个单词,如果您在输入字段中填写正确的答案,它就会变成绿色 我想向此代码添加功能,但我不知道如何添加我想编辑它,所以如果你输入错误的答案,它就会变成红色 此刻,它只会
我正在将 TExtView、edittext 和 TExtView 膨胀到 listView 的适配器,以解决如下不同的问题: 你叫什么名字______。泰姬陵在 _______ 国家。_______
所以我有这一行: ArrayList operations(); 现在,这是我的 ArrayList 类和我的操作结构: typedef struct Operation { char key
我正在准备 Java 期末考试。我遇到一道题,需要填空。 需要填空的相关代码 ____ ____ C {} ____ B extends ____ , C {} 问题是:我可以插入所有这些空白来编译我
我正在尝试在 Objective C 中为 iOS 实现类似的功能。 填空(UITextField)应该是内联的,并且应该能够有自己的inputType。 此外,每个 View 都是 UITableV
这是一个有趣的问题。 Fill in the blanks of while loop without using any extra variables or functions of what i
我是一名优秀的程序员,十分优秀!