我今年11岁,热衷于学习Python的程序员。语义猜数字游戏错误 - Python3.x
1)我在编程猜数字游戏,当我问用户他们是否想再玩一次时,我得到一个语义错误(我认为这是描述它的正确方法),如果输入“no “,”n“,”NO“或”N“,if语句仍然执行,导致loop()
函数在计算分数后再次运行。看看下面的图片(抱歉,关于混乱的窗户)。
玩一次错误:https://i.stack.imgur.com/TsEyw.png
下面是对程序的其它部分的链接: https://gist.github.com/anonymous/f9be138e07c569b8721b990293d92314
(我只有8点声望),但我看着眼前这个片断:
def play_again():
again = input("\nWould you like to play again? y/n " + prompt)
if again.upper() == "Y" or "YES":
global gu_num
percent = gu_num * 10
score = 100 - percent
highscores = [{round: (score)}]
current_score = {round: (score)}
highscores.append(current_score)
print("Lets see if you can beat your score of " + str(current_score[round]) + ".\nHere we go!")
gu_num = 0
loop()
elif again.upper() == "N" or "NO":
print("Ok then.\nThank you for playing Guess The Number and I hope to see you again soon!\nThis game was created and devoloped by Kiran Patel (me), age 12. If you liked this game or want to talk to me about -->anything<--, please do email me at [email protected] It'll make me happy! Thank you for playing Guess the number with me.\n\n program was developed by Kiran Patel in 2017 ad.")
input("\n\nPress the enter key to exit")
quit()
else:
print("Sorry, I don't understand. Please try again:")
play_again()
2)我的代码开始处理文件的部分有类似的问题。当我输入“否”(表达式相同if
)时,程序将执行创建该文件的if语句部分(查看此图像:file saving result和此图像:file operations code)。请注意,'文件操作代码'图像会打印出文件保存错误消息,因为我没有在prog'/ files文件夹中写入烫发程序。我知道它已经尝试保存文件,因为打印出来的错误信息(我打算将错误信息打印出来)。
3)另外,有没有人知道#!/usr/bin/python
是什么意思?我知道它已经被标记出来了,但是我之前看到过它,我想知道它是什么意思。
与往常一样,任何帮助将 appreaciated,所以请不要犹豫,增加一些不直接相关的问题,因为我可能错过了它(除非它是完全不相关的)。
再次,在此先感谢您的帮助。
从基兰
你有没有想过阅读编程教程? – iehrlich
https://en.wikipedia.org/wiki/Shebang_(Unix) – iehrlich
关于正在执行的条件语句的错误分支 - 删除所有逻辑,并在您的条件中简单地打印要测试的表达式,例如'again.upper ()'。这应该让你了解为什么你的状况评估不正确。 – iehrlich