Testing User Response

In [2]:
def ask_ok(prompt):
    ok = input(prompt)
    ok = ok.lower()
    
    if ok in ['y', 'ye', 'yes', 'yeah']:
        return "Affirmative!"
    
    if ok in ['n', 'no', 'nop', 'nope', 'nay']:
        return "Negatory!"
    
    if ok == "":
        return "Cat got your tongue?"
    
    if ok != "":
        return "You're speaking gibberish!"
In [3]:
ask_ok("Enter yes or no: ")
Enter yes or no: yes
Out[3]:
'Affirmative!'
In [4]:
ask_ok("Enter yes or no: ")
Enter yes or no: nay
Out[4]:
'Negatory!'
In [5]:
ask_ok("Enter yes or no: ")
Enter yes or no: 
Out[5]:
'Cat got your tongue?'
In [6]:
ask_ok("Enter yes or no: ")
Enter yes or no: s.sdkfjskjhsfd
Out[6]:
"You're speaking gibberish!"
In [7]:
def ask_ok_bad(prompt):
    ok = input(prompt)
    ok = ok.lower()

    if ok == "":
        return "Cat got your tongue?"
    
    if ok != "":
        return "You're speaking gibberish!"
    
    if ok in ['y', 'ye', 'yes', 'yeah']:
        return "Affirmative!"
    
    if ok in ['n', 'no', 'nop', 'nope', 'nay']:
        return "Negatory!"
In [8]:
ask_ok_bad("Enter yes or no: ")
Enter yes or no: 
Out[8]:
'Cat got your tongue?'
In [9]:
ask_ok_bad("Enter yes or no: ")
Enter yes or no: lksfgjhsfgdjfg
Out[9]:
"You're speaking gibberish!"
In [10]:
ask_ok_bad("Enter yes or no: ")
Enter yes or no: yeah
Out[10]:
"You're speaking gibberish!"
In [11]:
def ask_ok(prompt):
    ok = input(prompt)
    ok = ok.lower()
    
    if ok in ['y', 'ye', 'yes', 'yeah']:
        return "Affirmative!"
    
    if ok in ['n', 'no', 'nop', 'nope', 'nay']:
        return "Negatory!"
    
    if ok == "":
        return "Cat got your tongue?"
    
    if ok:
        return "You're speaking gibberish!"
In [12]:
bool("")
Out[12]:
False
In [13]:
bool("yeah")
Out[13]:
True
In [14]:
bool([])
Out[14]:
False
In [15]:
bool([1,2,3,4])
Out[15]:
True
In [16]:
bool(0)
Out[16]:
False
In [17]:
bool(1)
Out[17]:
True
In [18]:
bool(-100)
Out[18]:
True
In [19]:
bool(232423)
Out[19]:
True
In [20]:
bool(0.0)
Out[20]:
False
In [21]:
bool(0.00000000001)
Out[21]:
True
In [22]:
ok = "yeah"
bool(ok)
Out[22]:
True
In [1]:
def ask_ok_better(prompt):
    ok = input(prompt)
    ok = ok.lower()
    
    if ok in ['y', 'ye', 'yes', 'yeah']:
        response = "Affirmative!"
    elif ok in ['n', 'no', 'nop', 'nope', 'nay']:
        response = "Negatory!"
    elif ok == "":
        response = "Cat got your tongue?"
    #elif ok != "":
    #    response = "You're speaking gibberish!"
    else:   
        response = "You're speaking gibberish!"

    return response
In [ ]: