2

How would I be able to 'move' the input function to be within a string? Basically I currently have this:

Age = 11    
sentence1 = input("Tomorrow I will be ___ years old!")     
while sentence1 != Age:  
    print("Nope, that's not it! Guess again!")  
sentence1 = input("Tomorrow I will be ___ years old!")

When I run this program the input or 'cursor' always appears at the end of the sentence but I would like for it to start after the "be" in the sentence.

Saket Khandelwal
  • 347
  • 1
  • 11
cappyt
  • 51
  • 1
  • You should fix your code, this will print "Nope, that's not it! Guess again!" forever if the user enters anything at all. – Olivier Melançon Sep 05 '18 at 03:37
  • 5
    This actually isn't so straightforward, despite how elementary it seems. – juanpa.arrivillaga Sep 05 '18 at 03:37
  • I think we can use the curses library for that – Olivier Melançon Sep 05 '18 at 03:39
  • You can't do this directly. You can use curses (on platforms that have it—Windows doesn't, out of the box), or a simpler console library that doesn't require alternate mode, or a higher-level console library like urwid, or manually printing terminal control sequences—but really, most of those are not much simpler than writing a GUI, so most people will teach you how to use Tkinter or Kivy or something before teaching any of those things. – abarnert Sep 05 '18 at 03:48
  • Also, besides the problem that you asked about and the one that Olivier mentioned, `input` returns a string, but `Age` is a number, so they will never be equal. – abarnert Sep 05 '18 at 03:49

1 Answers1

0

Try using this in which moves the cursor 15 places back. Code:

Age = 11    
sentence1 = input("Tomorrow I will be ___ years old! \x1B[15D")    
while sentence1 != Age:  
    print("Nope, that's not it! Guess again!")  
sentence1 = input("Tomorrow I will be ___ years old! \x1B[15D")

You can adjust the number according to the number of places you want to place the cursor.

Saket Khandelwal
  • 347
  • 1
  • 11