0

So I have a program here: https://repl.it/@cooperl2/Find-Student-Info-V4-FINAL-STABLE

Code:

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()

However, when I run it on my computer via double-clicking on my desktop, it looks like the attached image. and the program quits after the 3rd question and does not complete. Not sure why that is and why there are the weird symbols.

Picture of weird symbols in Python 3.7 on PC

CDJB
  • 14,043
  • 5
  • 29
  • 55
  • 1
    You're literally writing these symbols in your code: `sys.stdout.write("\033[F"); sys.stdout.write("\033[K")`, so I'm not sure what your question is – ForceBru Jan 23 '20 at 15:08
  • You're trying to use ANSI escape sequences and the normal Windows terminal can't do that – SyntaxVoid Jan 23 '20 at 15:08
  • This post should answer your question I guess : [How to make win32 console recognize ANSI/VT100 escape sequences?](https://stackoverflow.com/questions/16755142/how-to-make-win32-console-recognize-ansi-vt100-escape-sequences) – sxeros Jan 23 '20 at 15:13
  • OKay, im very new to programming. Could I build a GUI to get around this problem? Or is that so much work for something that has an easier fix? Perhaps using @sxeros link. However Im fairly new haha! –  Jan 23 '20 at 15:48

1 Answers1

1

These are ANSI escape sequences - \033[F is to move the cursor back to the previous line, and \033[K clears the current line. The issue you are noticing will occur when the terminal you run the program in does not recognise these escape sequences.

CDJB
  • 14,043
  • 5
  • 29
  • 55
  • Hm, is there a simple way to just make a line erase after typing and entering the input? That is what I was trying to do. –  Jan 23 '20 at 15:38