NameError: name 'n' is not defined [duplicate]

前提是你 提交于 2019-12-25 19:04:26

问题


This works in jupyter notebook but when I try to run it from the command line in PyCharm it says that 'n' is undefined. There are other functions that are mentioned at the end but the only one I care about right now is game_rules(game, balance, profit). When I go through the function and press 'n' so the rules get displayed I get an error. This same error has been showing up more and more every time I use software other than jupyter notebook (like JGrasp and PyCharm). Does this have to do with my terminal specifically?



''' 
from time import sleep

hochan_rules = """
The rules of HoChan are as follows:
Each round, a dice will be rolled.  Before the roll, you will be asked to guess
whether the sum of both dice will be even or odd; and you will be asked to place a bet on your guess
If you guess correctly, you will recieve a payout of the amount that you bet
If you guess incorrectly, your money is ours
'''


def game_rules(game, balance, profit):
    user_input = str(input("""
Welcome to %s!
Have you played %s before? If not, we can quickly go through the rules together
Press 'N' for the rules ||'Y' to contintue without the rules || 'M' to go to Main Menu || 'E' to Exit
""" % (game, game)))
    if game == 'HoChan':

   #right here is where I get the error.  I try and press n and I get a traceback error that tells me n is undefined 

        if user_input.lower() == 'n':
            print(hochan_rules)
            sleep(2)


game_rules(game='HoChan', balance=500, profit=0) 

来源:https://stackoverflow.com/questions/59041146/nameerror-name-n-is-not-defined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!