- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个学校评估,是为了制作一个 child 的拼写游戏,当玩家单击"is"时,它必须循环/重新启动。到目前为止,当我测试游戏时,询问玩家是否想再次玩的选项/easygui.buttonbox 以及再次玩或退出游戏的是/否选项没有出现。显示玩家最终得分后程序就会关闭。
这是我的游戏编码,我找不到我做错了什么,我尝试了 3 个建议来修复编码,但没有一个起作用。
import easygui
#Childs Litercay Game
#Charlotte Lowe 03/09/2015
#Declare Constants and Variables
Score = 0
PlayerAnswer = 0
playOn = 0
while playOn != "Yes":
playOn = easygui.buttonbox ("Hey there, are you ready to test your spelling?", choices = ["Yes"])
if "Yes":
PlayerName = easygui.enterbox ("Before we begin, what's your name?")
easygui.msgbox ("Hi " + PlayerName +"! Here are the rules of the game.")
easygui.msgbox ("There will be 3 words you can choose from, 2 will be incorrect and 1 will be right.")
easygui.msgbox ("All you have to do is select the correctly spelt word.")
easygui.msgbox ("For every right word you pick you will earn a point! There are 10 questions in this quiz")
easygui.msgbox ("Let's begin!")
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices = ["Awesome","Awsome","Awesom"])
if PlayerAnswer == "Awesome":
Score += 1
easygui.msgbox ("You're right! Your score is " + str(Score))
elif PlayerAnswer == "Awsome":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is " + str(Score))
elif PlayerAnswer == "Awesom":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["Becuse","Becus","Because"])
if PlayerAnswer == "Becuse":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "Becus":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "Because":
Score += 1
easygui.msgbox ("Correct! Your score is now " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["Morning","Moring","Morening"])
if PlayerAnswer == "Morning":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "Moring":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "Morening":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["Beleave","Believe","Belive"])
if PlayerAnswer == "Believe":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "Beleave":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "Belive":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["Jewelry","Jewlery","Jewley"])
if PlayerAnswer == "Jewelry":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "Jewlery":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "Jewley":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["Mispelled","Misspelled","Misspeled",])
if PlayerAnswer == "Misspelled":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "Mispelled":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "Misspeled":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["acceptable","aceptable","acceptble",])
if PlayerAnswer == "acceptable":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "aceptable":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "acceptble":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["calendar","calender","callendar",])
if PlayerAnswer == "calendar":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "calender":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "callendar":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["equepment","equiptment","equipment",])
if PlayerAnswer == "equipment":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "equiptment":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "equipment":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["library","liebary","libary",])
if PlayerAnswer == "library":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "liebary":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "lieberry":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
if Score == 10:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, you got them all right " + PlayerName+ "!")
elif Score == 9:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, one away " + PlayerName+ "!")
elif Score == 8:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, so close "+ PlayerName+"!")
elif Score == 7:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, nearly there " + PlayerName+"!")
elif Score == 6:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, amlost made it " + PlayerName+ "!")
elif Score == 5:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, half way there " + PlayerName+ "!")
elif Score == 4:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, a little more pratice " + PlayerName+ "!")
elif Score == 3:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, pratice makes perfect "+ PlayerName+"!")
elif Score == 2:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, try again " + PlayerName+"!")
elif Score == 1:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, better luck next time " + PlayerName+ "!")
elif Score == 0:
easygui.msgbox ("You got a score of " + str(Score) + "out of 10, better luck next time " + PlayerName+ "!")
while playOn != "Yes":
playOn = easygui.buttonbox ("Do you want to play again?", choices = ["Yes", "No"])
if playOn == "Yes":
Score = 0 #resets score count, if player wants to play again
elif playOn == "No":
easygui.msgbox ("Bye for now. Hope you'll play the game again soon!")
我希望万维网上有人能够发现我做错了什么。我对 python 很陌生,所以我能得到的任何帮助都会很棒。我知道我之前曾就这段代码寻求过帮助,但我今天才刚刚注册了一个帐户,所以我不知道如何回复任何评论或任何东西!
最佳答案
要在用户回答"is"时再次玩游戏,您需要将游戏置于 while
循环中。对游戏进行最小程度的更改后,它可能看起来像:
import easygui
#Childs Litercay Game
#Charlotte Lowe 03/09/2015
#Declare Constants and Variables
Score = 0
PlayerAnswer = 0
playOn = 0
while playOn != "Yes":
playOn = easygui.buttonbox ("Hey there, are you ready to test your spelling?", choices = ["Yes"])
if "Yes":
PlayerName = easygui.enterbox ("Before we begin, what's your name?")
easygui.msgbox ("Hi " + PlayerName +"! Here are the rules of the game.")
easygui.msgbox ("There will be 3 words you can choose from, 2 will be incorrect and 1 will be right.")
easygui.msgbox ("All you have to do is select the correctly spelt word.")
easygui.msgbox ("For every right word you pick you will earn a point! There are 10 questions in this quiz")
easygui.msgbox ("Let's begin!")
while True:
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices = ["Awesome","Awsome","Awesom"])
if PlayerAnswer == "Awesome":
Score += 1
easygui.msgbox ("You're right! Your score is " + str(Score))
elif PlayerAnswer == "Awsome":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is " + str(Score))
elif PlayerAnswer == "Awesom":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["Becuse","Becus","Because"])
if PlayerAnswer == "Becuse":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "Becus":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "Because":
Score += 1
easygui.msgbox ("Correct! Your score is now " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["Morning","Moring","Morening"])
if PlayerAnswer == "Morning":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "Moring":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "Morening":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["Beleave","Believe","Belive"])
if PlayerAnswer == "Believe":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "Beleave":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "Belive":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["Jewelry","Jewlery","Jewley"])
if PlayerAnswer == "Jewelry":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "Jewlery":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "Jewley":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["Mispelled","Misspelled","Misspeled",])
if PlayerAnswer == "Misspelled":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "Mispelled":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "Misspeled":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly____
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["acceptable","aceptable","acceptble",])
if PlayerAnswer == "acceptable":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "aceptable":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "acceptble":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["calendar","calender","callendar",])
if PlayerAnswer == "calendar":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "calender":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "callendar":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["equepment","equiptment","equipment",])
if PlayerAnswer == "equipment":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "equiptment":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "equipment":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices =["library","liebary","libary",])
if PlayerAnswer == "library":
Score += 1
easygui.msgbox ("Well done! Your score is now " + str(Score))
elif PlayerAnswer == "liebary":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
elif PlayerAnswer == "lieberry":
Score += 0
easygui.msgbox ("Sorry Incorrect! Your score is still " + str(Score))
print(Score) #To check if programme is calculating score properly
if Score == 10:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, you got them all right " + PlayerName+ "!")
elif Score == 9:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, one away " + PlayerName+ "!")
elif Score == 8:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, so close "+ PlayerName+"!")
elif Score == 7:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, nearly there " + PlayerName+"!")
elif Score == 6:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, amlost made it " + PlayerName+ "!")
elif Score == 5:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, half way there " + PlayerName+ "!")
elif Score == 4:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, a little more pratice " + PlayerName+ "!")
elif Score == 3:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, pratice makes perfect "+ PlayerName+"!")
elif Score == 2:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, try again " + PlayerName+"!")
elif Score == 1:
easygui.msgbox ("You got a score of " + str(Score) + " out of 10, better luck next time " + PlayerName+ "!")
elif Score == 0:
easygui.msgbox ("You got a score of " + str(Score) + "out of 10, better luck next time " + PlayerName+ "!")
playOn = easygui.buttonbox ("Do you want to play again?", choices = ["Yes", "No"])
if playOn == "Yes":
Score = 0 #resets score count, if player wants to play again
elif playOn == "No":
easygui.msgbox ("Bye for now. Hope you'll play the game again soon!")
break
计算机比人类更擅长重复性的事情。修改以下代码以利用这一点:
import easygui
#Childs Litercay Game
#Charlotte Lowe 03/09/2015
def play(choices, answer, Score):
"""Check spelling."""
PlayerAnswer = easygui.buttonbox ("Which word is spelt correctly?", choices=choices)
if PlayerAnswer == choices[answer]:
Score += 1
easygui.msgbox ("You're right! Your score is " + str(Score))
else:
easygui.msgbox ("Sorry Incorrect! Your score is " + str(Score))
return Score
# print(Score) #To check if programme is calculating score properly
tests = (
(["Awesome","Awsome","Awesom"], 0),
(["Becuse","Becus","Because"], 2),
(["Morning","Moring","Morening"], 0),
(["Beleave","Believe","Belive"], 1),
(["Jewelry","Jewlery","Jewley"], 0),
# Fill in the rest.....
)
congrats = {
10:"you got them all right ",
9:"one away",
8:"so close",
7:"nearly there",
6:"amlost made it",
5:"half way there",
4:"a little more pratice",
3:"pratice makes perfect",
2:"try again",
1:"better luck next time",
0:"better luck next time",
}
# Hello and instructions
playOn = easygui.buttonbox ("Hey there, are you ready to test your spelling?", choices = ["Yes"])
PlayerName = easygui.enterbox ("Before we begin, what's your name?")
easygui.msgbox ("Hi " + PlayerName +"! Here are the rules of the game.")
easygui.msgbox ("There will be 3 words you can choose from, 2 will be incorrect and 1 will be right.")
easygui.msgbox ("All you have to do is select the correctly spelt word.")
easygui.msgbox ("For every right word you pick you will earn a point! There are 10 questions in this quiz")
easygui.msgbox ("Let's begin!")
while True:
Score = 0
for choices, answer in tests:
Score = play(choices, answer, Score)
print(Score) #To check if programme is calculating score properly
easygui.msgbox (congrats[Score] +" " + PlayerName+ "!")
playOn = easygui.buttonbox ("Do you want to play again?", choices = ["Yes", "No"])
if playOn == "No":
easygui.msgbox ("Bye for now. Hope you'll play the game again soon!")
break
注释:
为用户提供三个选择并更新分数的代码现在在一个函数中出现一次,该函数会为每组选择调用多次。
总结用户表现的代码被减少到几行,并从字典中获取鼓励的话。
关于Python程序不循环/重新启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27009710/
我搜索了重启我的 android 应用程序的替代方法,但我发现重启的唯一方法是使用 Flex 构建. 我可以用 as3 flash 重启我的 android adobe air 应用程序吗?我该怎么做
我有一个学校评估,是为了制作一个 child 的拼写游戏,当玩家单击"is"时,它必须循环/重新启动。到目前为止,当我测试游戏时,询问玩家是否想再次玩的选项/easygui.buttonbox 以
在.yml文件中,我定义了:restart: always。是否可以将此重启创建为--force-recreate标志的等效项? 我的XVFB有问题,标准重启无法解决问题,但通过--force-rec
我正在尝试重新启动 while 循环。我已经声明了 boolean 类型的变量 keepGoing 。如果 int 变量 x 超出窗口,则 keepGoing 更改为 false。然后reset()方
如何使用 Cast SDK 或其他方式让我的应用以官方 Chromecast 应用的方式触发 Chromecast 重启? 如果是“否则”,Google Play 可能会对这种做法不友善吗? 最佳答案
运行/etc/init.d/postgresql restart有没有危险?我们刚刚发生了一些关系“消失”的事件,我运行了上述命令。刚刚被系统管理员骂了一顿,但是他没有解释为什么这是一件坏事。我确实将
是否可以重新启动 while 循环?我目前在 foreach 循环中存在一个 while 循环,并且每次都需要 while 语句从头开始。 $sql = mysqli_query($link, "SE
我有如下倒计时器: - (void)updateCounterLabel:(NSTimer *)theTimer { if(secondsLeft > 0 ){ secondsLeft
就像我在 python 中一样。 choice1 = raw_input('John Blue Green') if choice1 == 'A': print('blah') elif cho
我的游戏在 True 循环中运行一段时间,我希望能够要求用户“再玩一次?”我已经有了用于弹出文本的矩形的代码,但我需要一种方法让用户单击矩形或按 y 表示是,然后代码再次自行运行。 最佳答案 在您的主
我是 nginx 的初学者。我正在使用 Ubuntu 16.04。我按照步骤操作, sudo apt-get 更新。 sudo apt-get install nginx sudo apt-get 升
我需要使用 javascript 重放一个 css 转换。当我重置我的 div 的 css 样式并应用新的过渡时,没有任何反应...... 我认为这两个代码是在同一个执行框架中执行的,并且通过优化,它
所以我有这几行代码: string[] newData = File.ReadAllLines(fileName) int length = newData.Length; for (int i =
所以我有一个计时器,每 5 秒旋转一组图像。因此,我在文档启动时运行它。 $(document).ready(function() { var intervalID=setInterval(funct
好吧,我在重新启动 Apache 服务器时遇到了一些问题。我修改了服务器上的 ulimit 但我无法重新启动 httpd; 我在 CentOS 5.8 x64 上运行服务器. httpd -V 的输出
我在使用 docker 时遇到问题 docker ps不会返回并被卡住。 我发现做 docker service restart 之类的sudo service docker restart (htt
从 .net 代码停止和重新启动 Storyboard的正确方法是什么? 我想 ... myStory.Stop(this); 期望随后调用 .Begin(this);将从零开始从时间线重新开始,但
我有一个带有一些缓存后端的应用程序,我想在重新启动网络服务器时清除缓存。 在网络服务器(重新)启动时是否有 apache 配置指令或任何其他方式来执行 shell 脚本? 谢谢, 菲尔 正如一些答案已
我愿意在我的应用程序中添加一个按钮,单击该按钮将重新启动应用程序。我搜索了谷歌,但发现除了 this one 没有任何帮助.但是这里遵循的程序违反了 Java 的 WORA 概念。 是否还有其他以 J
我们目前遇到间歇性邮件队列中断。我是 seeking diagnostic help in another area . 同时,有没有办法在不重启整个服务的情况下重启CF邮件队列? CF8标准 Win
我是一名优秀的程序员,十分优秀!