Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cannot figure out
#1
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
Reply
#2
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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020