-2

I've to make this code where I have to take a customers order and then take a form of payment. For the card payment I was wondering if there was a way to have the input replaced with asterisks as they were typed. There is a line where I ask them to input their pin which is as follows:

pin=input("Insert your pin") #Asks user for pin number.

Let's say the pin is 1234. Instead of it showing 1234 as it is typed, is there a way to make it go **** when it's being typed. I've tried using .getpass(); whether or not I've used it right I don't know. Any help would be appreciated.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • Can't be totally sure, but isn't this a duplicate of https://stackoverflow.com/q/27631629/3934789 ? – Cliabhach Dec 04 '17 at 09:43
  • 1
    You said you've tried `getpass`. What's wrong with that? – khelwood Dec 04 '17 at 09:44
  • 1
    Please show us what you have tried. – mrCarnivore Dec 04 '17 at 09:44
  • With regards to getpass, I imported it at the start of the code and tried to put it at the end of the input line. – Marshall Shaw Dec 04 '17 at 09:49
  • 2
    Show real code. We cannot guess *exactly* what you have done without it. Hell lies in the detail... – Serge Ballesta Dec 04 '17 at 09:56
  • paymentType=input("Card or Cash? ").lower() #Asks the user how they'd like to pay. if paymentType == "card": #Recognises the user said card. print("Insert card into reader and follow on-screen instructions") #Telling the customer what they've to do. time.sleep(4) #Wait 4 seconds for effect. pin=input("Insert your pin") #Asks user for pin number. time.sleep(2) #Waits 2 seconds for effect. print("Thank you! Have a nice day") #End of the sale. break #End of the program. – Marshall Shaw Dec 04 '17 at 09:57
  • That's what I use for the card input – Marshall Shaw Dec 04 '17 at 09:57
  • @MarshallShaw So you haven't tried `getpass` ... ? – khelwood Dec 04 '17 at 10:28

1 Answers1

0

Getpass would usually just be used like:

from getpass import getpass

pin = getpass()

Worth noting in some IDEs can cause problems. See here for example.

Philip
  • 157
  • 1
  • 10