import random |
print ( "-------欢迎来到千词斩--------" ) |
questionList = [ "随机" , "错误" , "继续" , "硬币" , "答案" , "如果" , "否则" , "打印" , "收入" , "问题" ] #中文 |
answerList = [ "random" , "error" , "continue" , "coin" , "answer" , "if" , "else" , "print" , "input" , "question" ] #单词 |
while True : |
index = random.randint( 0 , 9 ) |
question = questionList[index] |
if question = = None : |
continue |
|
answer = answerList[index] |
|
user = input ( "请问" + question + "的英文单词是:" ) |
|
if user = = answer: |
count = count + 1 |
if count = = 10 : |
print ( "你背完了" ) |
break |
questionList[index] = None |
print ( "你答对了" ) |
else : |
print ( "你打错了" ) |
by: FJY 发表于:2020-12-02 00:03:51 顶(1) | 踩(0) 回复
#大佬帮忙看看,本人初学,借鉴您的代码,拿简单的函数堆了一个效果差不多的
#use:python3
import os
import random
whichlist=[0,1,2,3,4,5,6,7,8,9]
#中文词汇表↓
ChineseList=["随机","帮助","结果","选择","答案","如果","否则","打印","收入","问题"]
#英文词汇表↓
EnglishList=["random","help","result","choice","answer","if","else","print","input","question"]
#词汇可自行增加
#加入词汇时,ChineseList和EnglishList中的元素必须一一对应,每加入一个词汇,就要在whichlist中加入一个数
print("________________")
print("\nHi~ o(* ̄▽ ̄*)ブ")
print("欢迎来到千词斩\n")
print("﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍\n")
print("共有",len(whichlist),"个单词\n")
number = int(input("请问您想背几个单词?"))
now = int(0)
while number > len(whichlist):
print("\n!┅┅┅┅┅┅┅┅┅┅!")
print(" 数值大于总词汇数")
print(" 请重新输入")
print(" 共有",len(whichlist),"个单词\n")
number = int(input("请问您想背几个单词?"))
now = int(0)
print("\n1:看中文写英文")
print("2:看英文写中文\n")
choice=input("请问您想选择哪种?")
while now != number:
which = random.choice(whichlist)
Chinese = ChineseList[which]
English = EnglishList[which]
if choice == "1":
answer = input("请问"+Chinese+"的英文是什么")
if answer == English:
print("答对了")
now += 1
whichlist.remove(which)
else:
print("答错了")
elif choice == "2":
answer = input("请问"+English+"的英文是什么")
if answer == Chinese:
print("答对了")
now += 1
whichlist.remove(which)
else:
print("答错了")
else:
print("\n此为无效命令")
print("请输入1或2")
print("1:看中文写英文")
print("2:看英文写中文\n")
choice=input("请问您想选择哪种?")
print("恭喜你,你背完单词了")
初级程序员
by: FJY 发表于:2020-11-17 18:46:57 顶(4) | 踩(1) 回复
您好,您没有在while循环前给count赋值,这样程序会报错的
回复评论