首页 > 解决方案 > Python程序在输入换行符后有奇怪的符号?程序在在线编辑器中工作

问题描述

所以我在这里有一个程序:https ://repl.it/@cooperl2/Find-Student-Info-V4-FINAL-STABLE

代码:

import datetime
import sys

def find_info():
  first_name = input("What is your first name? ").lower()
  sys.stdout.write("\033[F")
  sys.stdout.write("\033[K")

  last_name = input("What is your last name? ").lower()
  sys.stdout.write("\033[F")
  sys.stdout.write("\033[K")

  grade = input("What grade are you in? ").lower()
  grade = int(grade[0])
  sys.stdout.write("\033[F")
  sys.stdout.write("\033[K")

  year = datetime.date.today().year
  month = datetime.date.today().month
  shift = 1 if datetime.date.today().month < 9 else 0
  sys.stdout.write("\033[F")
  sys.stdout.write("\033[K")

  pin = input("What is your lunch pin / ID number? ")
  sys.stdout.write("\033[F")
  sys.stdout.write("\033[K")

  grad_year = year + 13 - grade - shift
#this replaces the entire if statement in the V3 -- See V3 for details.

  print("Hello there " + first_name+"!") 
  print("\n")
  print("Your username is: " + last_name.lower() + first_name[0].lower() + str(grad_year)[2]+ str(grad_year)[3])
  print("Your password is: " + first_name[0].lower() + last_name[0].lower() + pin + "hoh")
  print("Your Email Address is: " + last_name.lower() + first_name[0].lower() + str(grad_year)[2]+ str(grad_year)[3] + "@learn.hohschools.org")

find_info()

但是,当我通过双击我的桌面在我的计算机上运行它时,它看起来像附加的图像。并且程序在第三个问题后退出并且没有完成。不知道为什么会这样以及为什么会有奇怪的符号。

PC上Python 3.7中奇怪符号的图片

标签: pythonpython-3.xprintingconsole

解决方案


这些是ANSI 转义序列-\033[F将光标移回上一行,并\033[K清除当前行。当您在其中运行程序的终端无法识别这些转义序列时,将出现您注意到的问题。


推荐阅读