python新手,尝试猜谜游戏。我正在使用pycharm。继承人的代码后跟错误这是我的代码代码:import randomlucky number= random.randrange(1,100)guess = int(input('guess the number in the range 1-100: '))while guess != lucky number: if guess < lucky number: print ("too low, try higher") guess = int(input("\n Guess a number between 1-100") else: print ("too high, try lower") guess = int(input("\n Guess a number between 1-100"))print ("you guessed the number correctly, Congratulations!")import randomlucky number= random.randrange(1,100)guess = int(input('guess the number in the range 1-100: '))while guess != lucky number: if guess < lucky number: print ("too low, try higher") guess = int(input("\n Guess a number between 1-100") else: print ("too high, try lower") guess = int(input("\n Guess a number between 1-100"))print ("you guessed the number correctly, Congratulations!")这是错误: Error:Traceback (most recent call last): File "<input>", line 1, in <module> File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.4\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.4\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 11, in execfile stream = tokenize.open(file) # @UndefinedVariable File "C:\Users\Shane McDonagh\AppData\Local\Programs\Python\Python38-32\lib\tokenize.py", line 392, in open buffer = _builtin_open(filename, 'rb')FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/Shane McDonagh/.PyCharmCE2019.3/config/scratches/scratch_1.py'
3 回答
12345678_0001
TA贡献1802条经验 获得超5个赞
它说random
图书馆不存在。这要么是由于您没有通过安装它,pip
要么是 pycharm 没有正确设置正确的配置。由于random
是默认库,与大多数其他库不同,您不需要通过pip
命令安装它。所以你必须修复你的配置。O 在屏幕的右上角File > Settings > Project: project-name > Project Interpreter
编辑您的配置,或者完全删除您的配置并创建一个新配置,或者选择一个不同的现有配置。
也不要import
在文件上多次使用相同的语句,这可能会导致大量错误和问题,我假设您不小心粘贴了两次代码,但我想指出以防万一。
慕斯709654
TA贡献1840条经验 获得超5个赞
FileNotFoundError:[Errno 2] 没有这样的文件或目录:'C:/Users/Shane McDonagh/.PyCharmCE2019.3/config/scratches/scratch_1.py'
此错误表示您尝试运行的文件不存在。它什么也没说random
。要修复错误,只需右键单击编辑器选项卡并选择运行。这应该为该特定文件创建一个新的运行配置。如果这不能解决问题,请删除所有运行配置并重试。
添加回答
举报
0/150
提交
取消