JavaScript
x
11
11
1
def are_you_playing_banjo(name):
2
first_char = name[0]
3
if first_char != "r" or "R":
4
outcome = name + " does not play banjo"
5
else:
6
outcome = name + " plays banjo"
7
return outcome
8
9
p = are_you_playing_banjo("rick")
10
print (p)
11
**This should print “{name} plays banjo” because the name starts with “r” and I suspect that there is something wrong with how I selected the first character of the string and used it in an if statement. **
Advertisement
Answer
Python has a string method startswith()
which will do what you need.
Replace
JavaScript
1
3
1
first_char = name[0]
2
if first_char ..
3
With a single if statement
JavaScript
1
2
1
if not name.lower().startswith("r"):
2