How can I make my program work so that if I say
Enter C for Cake and CA for cookie, If they enter C, they don't have to hit return?
You can't, remember that
CA would be ambiguous from
C as the first key is both
What you should do instead is:
from getch import getch key = getch() if key == 'C': print('Cake') elif key == 'A': print('COOKIE')
As you can see, if the user typed in C, you would either have to get input again or else it will always become Cake.
try this code.
import getch inp = getch.getch() print("Enter C for Cake and CA for cookie") if inp == "C": print("cake") else: print("Cookie")
That should work
Try import getch. Then do
answer = getch.getch() (this will cause them not to see what they type) or
answer = getch.getche()which won't. However this is only for a single character so change CA to something like B.