2016-06-22 25 views
-2

次のコードはIDLEで正しく実行されますが、コンソールでエラーを返します。私のpythonスクリプトはIDLEでは動作しますが、コンソールでは動作しません

import sys, math, string, time, os 
from time import * 
restart0 = True 
while restart0: 
    def addDecimal(): 
     print(".", end="\r") 
    breakout0 = False 
    invalidcommand0 = True 
    while invalidcommand0: 
     file = open("HighScores.txt","r+") 
     sleep(0.5) 
     print("\nWelcome to VACSecureServers™\n") 
     start = input("Would you like to start the program? ") 
     if start.lower() == "yes": 
      print("\n1. Display high scores\n2. Add a new high score\n3. Clear all high scores\n4. Quit") 
      option = input() 
      if option == "1": 
       print (file.read()) 
       if os.stat("highscores.txt").st_size==0: 
        print("There are no highscores currently in the system, please return and input some.") 
      elif option == "2": 
       numberAppend = int(input("How many scores would you likes to add to the program? ")) 
       for loop in range(numberAppend): 
        name = input("Enter the name of the user:") 
        score = input("Enter a score: ") 
        file.write(name+","+score+","+strftime("%d/%m/%y %H:%M:%S\n")) 
      elif option == "3": 
       open("HighScores.txt", 'w').close() 
       print("Highscores resetting") 
       sleep(0.4) 
       addDecimal() 
       sleep(0.6) 
       addDecimal() 
       sleep(0.9) 
       addDecimal() 
       sleep(1.2) 
       print("Successfully reset!") 
       sleep(2) 
      elif option == "4": 
       sys.exit() 
     file.close() 

これは私が取得エラーです:

Traceback (most recent call last): 
File "E:\script.py", line 12, in <module> 
    print("\nWelcome to VACSecureServers™\n") 
File: "C:\Python3\lib\encodings\cp437.py", line 19, in encode 
    return codecs.charmap_encode(input,self.errors,encoding_map)[0] 
UnicodeEncodeError: 'charmap' codec can't encode character '\u2122' in position 29: character maps to <undefined> 

問題がある可能性がありますか?

+2

何が起こると思いますか?何がうまくいかない?コードをレイアウトして有効にして読むことができますか?ありがとう – doctorlove

+0

私はそれをレイアウトしました私はそれを貼り付けるためにコードサンプルを使用しなければならなかったことを私は知らなかったので、stackoverflowにちょうど新しいです – PCGamer101

+1

あなたは問題の実際の説明にこの不器用さを置き換えることができます。また、ポストのコードを4つの空白でインデントすると、色付けが可能になります。 –

答えて

0

それはあなたがそれにシンボルを持っているので、このラインの

print("\nWelcome to VACSecureServers™\n") 

です。あなたのコンソールはおそらくそれを表示することはできませんが、IDLEはユニコード文字をサポートしています。それを削除すれば、コードはうまくいくはずです。

関連する問題