+ 2

Can anybody help me how to write this function.. I tried several methods but unable to write the correct code..

#Imagine you're writing a cash register application. To make #interaction easier on the user, it doesn't have separate #areas for passwords, PIN numbers, or cash totals -- #instead, it looks at what the cashier enters and infers #whether it's their PIN number, their password, or the cash #total for a transaction. # #The register makes this decision with the following rules: # # - If the cashier entered only digits, then it's a PIN # number. # - If the cashier entered a decimal number, then it's the # transaction amount. # - If the cashier entered anything else, then it's their # password. # #Write a function named interpretCashier. interpretCashier #should take one parameter as input, which will always be #a string initially. # # - If the string entered represents a PIN number, return # "PIN". # - If the string entered represents a transaction amount, # return "Transaction". # - If the string entered represents a password, return # "Password". # #Hint: There is a very easy way to do this, and a very hard #way to do this. Remember, this test is on control #structures, not strings. #Write your function here! # if not Transaction and not Password: # PIN = True # return "PIN" # print("Password=", Password) # print("Trans=", Transaction) # print("PIN = ", PIN) #The lines of code below will test your function. It is not #used for grading, so feel free to change it. As written, #these lines should print Transaction, PIN, and Password, #each on a separate line. print(interpretCashier("2459.")) #print(interpretCashier("123456")) #print(interpretCashier("my$up3rs3cur3p4$w0rd")) #print(interpretCashier("25.0"))

6th Sep 2020, 6:37 PM
NG_
NG_ - avatar
6 Respuestas
+ 7
Nethra Gurumurthy If you need help, you can post the code you're struggling with. Try to search for similar questions or answers before posting and include relevant tags!  • https://www.sololearn.com/post/75089/?ref=app
6th Sep 2020, 7:37 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 6
Try yourself I will help you only . show your attempt
6th Sep 2020, 6:40 PM
Sâñtôsh
Sâñtôsh - avatar
+ 5
What have you tried atleast? Show it
6th Sep 2020, 6:59 PM
Nilesh
Nilesh - avatar
+ 2
Pls share your attempt.. In the description code , you are taking input and main part..?
6th Sep 2020, 7:19 PM
Jayakrishna 🇮🇳
0
Thank you all for your input. i finally figured it out. def interpretCashier(my_string): numlist = ["0","1","2","3","4","5","6","7","8","9"] allnumber = False foundchara = False i = 0 for chara in my_string: if chara in numlist: allnumber = True else : foundchara = True nextchara = my_string[i+1] break i +=1 if foundchara == True and chara == "." and nextchara != "." : return "Transaction" elif foundchara == False and allnumber == True: return "PIN" else: return "Password"
6th Sep 2020, 8:15 PM
NG_
NG_ - avatar
0
def interpretCashier(a): try: bool(int(a)) == True return "PIN" except ValueError: return "Password" I tried this but I am facing a problem as I am getting Password two times, the decimal part in which I am getting password is wrong and how should I make it right?? Any suggestions??
16th Jan 2021, 10:34 AM
Akash Goyal
Akash Goyal - avatar