-1

I built a simple text game in python to show a friend, and it runs fine on shell but errors in terminal. Is there a difference in compiling for terminal vs shell in python?

In shell, this is what happens: test is an invalid input, so it asks you to type one of the answers and then when typing yes it continues

But in terminal it gives me this error: enter image description here

Is there any reason for this?

My code:

"""""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~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".')
UnsignedByte
  • 849
  • 10
  • 29

1 Answers1

5

It looks like you are using Python 3.x in the shell but Python 2.x is used in the terminal. The input() function behaves differently in the two versions of Python.

Just make sure you are using Python 3.x in the terminal. If you want Python 2.x both times, change input() to raw_input().

Rory Daulton
  • 21,934
  • 6
  • 42
  • 50