-2

I want the script to check if the user inputted the letter "b" at the beginning of his input

here is my code:

word = raw_input("Enter the magic word:");
print "your magic word is %s" % (word);

if he didn't enter the letter "b" at the beginning, the script will automatically add it.

any help is appreciated.

Aleana
  • 13
  • 1

2 Answers2

2

I am not telling you how to finish your checking but you should use startswith:

>>> if word.startswith('b'):
...     print "Hei"
... else:
...     print "No"
Sharif Mamun
  • 3,508
  • 5
  • 32
  • 51
1

There's no need to add semicolon in Python

word = raw_input("Enter the magic word:")
word = word if word.startswith('b') else 'b' + word
print "your magic word is %s" % (word)
Tim
  • 41,901
  • 18
  • 127
  • 145
laike9m
  • 18,344
  • 20
  • 107
  • 140