-1

When I run the code and input "1" or "2" it gives me the response

Sorry, we didn't understand your selection.

How do I fix this so that it gives me the correct answer?

I've Tried making "1" and "2" a string.

def cs_service_bot():
    # Replace `pass` with your code
    response = input("Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer? \n [1] New Customer \n [2] Existing Customer \n Please enter the number corresponding to your choice:")
    if response == "1":
        return new_customer()
    elif response == "2":
        return existing_customer()
    else:
        print("Sorry, we didn't understand your selection.")
        return cs_service_bot()

cs_service_bot()

No error messages, It won't give me the answer I am looking for which is either one of these functions: new_customer() or existing_customer()

martineau
  • 119,623
  • 25
  • 170
  • 301
Da Ridg
  • 3
  • 4

2 Answers2

0

Try by converting response in to string and then compare.

def cs_service_bot():
    # Replace `pass` with your code
    response = input("Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer? \n [1] New Customer \n [2] Existing Customer \n Please enter the number corresponding to your choice:")
    if str(response) == "1":
        return new_customer()
    elif str(response) == "2":
        return existing_customer()
    else:
        print("Sorry, we didn't understand your selection.")
        return cs_service_bot()

cs_service_bot()
Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61
0

If you are using python2 ,input is returning integer, so you need do to:

response = input("Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer? \n [1] New Customer \n [2] Existing Customer \n Please enter the number corresponding to your choice:")
if response == 1:
    return new_customer()

or:

response = input("Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer? \n [1] New Customer \n [2] Existing Customer \n Please enter the number corresponding to your choice:")
if str(response) == "1":
    return new_customer()

Examples:

Python 2.x
s1 = raw_input("Enter raw_input to test raw_input() function: ")
>> 3
print (type(s1))  <type 'str'>
s11 = raw_input("Enter raw_input to test raw_input() function: ")
>> a
print (type(s11))  <type 'str'>


s2 = input("Enter input to test input() function: ")
>> 3 
print (type(s2))  <type 'int'>
s22 = input("Enter input to test input() function: ")
>> a
print (type(s22))  <type 'str'>


Python 3.x
s3 = input("Enter input to test input() function: ")
>> 1
print (type(s3))  <type 'str'>
s33 = input("Enter input to test input() function: ")
>> a
print (type(s33))  <type 'str'>

EDIT:

def new_customer():
    print ("new_customer")

def existing_customer():
    print ("existing_customer")

def cs_service_bot():
    # Replace `pass` with your code
    response = input("Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer? \n [1] New Customer \n [2] Existing Customer \n Please enter the number corresponding to your choice:")
    if response == "1":
        return new_customer()
    elif response == "2":
        return existing_customer()
    else:
        print("Sorry, we didn't understand your selection.")
        return cs_service_bot()

cs_service_bot()

output:

Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer? 
 [1] New Customer 
 [2] Existing Customer 
 Please enter the number corresponding to your choice:1
new_customer
ncica
  • 7,015
  • 1
  • 15
  • 37