-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,275
  • 5
  • 30
  • 50
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
  • 39,651
  • 17
  • 123
  • 137
laike9m
  • 16,616
  • 19
  • 96
  • 130