Python Forum
cannot figure out - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: cannot figure out (/thread-2541.html)



cannot figure out - rturus - Mar-23-2017

Whatever I entered into variable 'ti' it works. I thought if I enter t, T, I or i should have worked. Even if I enter number it works. Can't figure out.  Any help please?

thanks.
print('welcome to abc college competition')
print('we have a competition on the following events')
print('\n\tHistory \n\tGeography \n\tFootball \n\tMusic\n\tTheory questions')
ti=str(input('if you wish to join as a team press t or as an individual press i '))
if ti=='t' or ti=='T' or ti=='i' or ti=='I':        #print

    name=input('enter the team or individual name:  ')
    if ti=='t' or ti=='T':
            print ('you have joined as a team and the name of the team is ',name)
    elif ti=='i' or ti=='I':
            print ('you have joined as an individual and the name of the individual is',name)
    else:
            print ('incorrect input')
Moderator snippsat: Addded code tag look at BBcode help


RE: cannot figure out - nilamo - Mar-23-2017

I can't reproduce the issue, so please show us the output you're getting (your code looks fine to me, though I'd suggest using .lower() instead of handling both upper and lower case characters... or using "in" like if ti in "tTiI", or both: if ti.lower() in "it"):

>>> ti = input("? ")
? spam
>>> if ti=='t' or ti=='T' or ti=='i' or ti=='I':
...  print("Yep")
... else:
...  print("Nope")
...
Nope