2016-12-31 25 views
-1

我在python中构建了一个简单的文本游戏来展示一个朋友,它在shell中运行良好,但在终端中出错。 python中的shell和shell编译有区别吗?终端上的Python 3与shell不同?

壳,这是发生了什么: test is an invalid input, so it asks you to type one of the answers and then when typing yes it continues

但在终端它给了我这个错误: enter image description here

有没有道理呢?

我的代码:

"""""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~IMPORT PACKAGES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~""""" 

from random import randint 
import os 
import copy 
import math 
import time 
import pickle 
import platform 
import subprocess as sp 

"""""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~LOAD DATA/NEW GAME~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~""""" 

newData = {"assassin" : {'hp' : 100, 'atk' : 250, 'lvl' : 1, 'arm' : 0, 'pow' : {'name' : 'surprise attack', 'lvl' : 0}, 'xp' : 0}, 
          "mage" : {'hp' : 100, 'atk' : 200, 'lvl' : 1, 'arm' : 0, 'pow' : {'name' : 'fire','lvl' : 0}, 'xp' : 0}, 
          "knight" : {'hp' : 100, 'atk' : 150, 'lvl' : 1, 'arm' : 10, 'pow' : {'name' : 'dodging','lvl' : 0}, 'xp' : 0}, 
          "healer" : {'hp' : 500, 'atk' : 50, 'lvl' : 1, 'arm' : 0, 'pow' : {'name' : 'healing','lvl' : 0}, 'xp' : 0}} 


if platform.system()=='Windows': 
    file = 'filepath' 
elif platform.system()=='Darwin': 
    file = 'filepath' 

"""Clears screen""" 
clear = lambda: os.system('cls' if platform.system()=='Windows' else 'clear') 

print('Load data?') 

while True: 
    answer = input() 


    if answer == 'yes': 
     load_file = open(file, 'rb') 
     characterData = pickle.load(load_file) 
     load_file.close() 
     break 
    elif answer == 'no': 
     print('Starting a new game...') 
     time.sleep(0.5) 
     characterData = copy.deepcopy(newData) 
     save_file = open(file, 'wb') 
     pickle.dump(characterData, save_file) 
     save_file.close() 
     break 
    else: 
     print('That input cannot be deciphered. Please type "yes" or "no".') 

回答

5

它看起来像你使用Python 3.X的外壳但是Python 2.x的是在终端使用。在两个版本的Python中,input()函数的行为有所不同。

只要确保您在终端中使用Python 3.x。如果您同时需要Python 2.x,请将input()更改为raw_input()

相关问题