-4

for example:

print ('Choose your character, Bob, a 19 year old student, or Craig, a 32 year old man')
resp = input

if ('Bob') in resp:
    print ('You have chosen Bob.')
elif ('Craig') in resp:
    print ('You have chosen Craig!')
else:
    print ('Invalid. Please check spelling')

please help, I am experimenting in Python ;)

Mathias
  • 6,777
  • 2
  • 20
  • 32
  • 2
    Did you even Google? – That1Guy Oct 16 '14 at 15:57
  • Indent correctly. To call the function, append `()` after the function name: `resp = input()`. No need to surround the string literals with `(..)`. – falsetru Oct 16 '14 at 15:58
  • Thanks falsetru, this is one of the first pieces of python I have coded and I am a bit lost :p – user3670603 Oct 16 '14 at 16:00
  • As a general note, Stack overflow usually shouldn't be your first stop when learning a new language. If you end up asking a question that can be quickly answered by [reading the docs](https://docs.python.org/2/library/string.html) or [taking a tutorial](https://developers.google.com/edu/python/?hl=de-DE), you're probably going to be quickly downvoted. Especially if your question [is a duplicate](http://stackoverflow.com/q/5319922/2615940). – skrrgwasme Oct 16 '14 at 16:03
  • thanks for the links, I wasn't aware of the Google tutorials. i won't dupe post again – user3670603 Oct 16 '14 at 16:11

1 Answers1

0

First, you need to actually call the input function. Secondly, your formatting will cause an IndentationError.

Now to answer your question. input will always return a string, I think you're asking how to check its value.

Try this:

resp = input('Choose your character, Bob, a 19 year old student, or Craig, a 32 year old man')
characters = ['Bob', 'Craig']

if resp in characters:
    print('You have chosen {}'.format(resp))
else:
    print('Invalid. Please check spelling')
That1Guy
  • 7,075
  • 4
  • 47
  • 59