Reputation: 19
I need help with the str.isupper() function. I am trying to use it in an if/elif/else statement. The program is this.
String = raw_input( 'Please enter a string. ')
if String[:1].isupper():
print 'The first character,' + string[0] ('is capitalized')
I am trying to make it so if you enter a capital it will print one thing and if it is not capitalized it will print something else. How would i do this?
Edit: I guess I don't understand how to make the program print the two situations. I get if/elif/else statements, but i don't understand them with the isupper() function. Please explain.
Upvotes: 0
Views: 1848
Reputation: 113864
The print statement required two minor corrections:
String = raw_input( 'Please enter a string. ')
if String[:1].isupper():
print 'The first character,' + String[0] + ', is capitalized'
The first was that String
needed to be capitalized. and the second was to remove the parentheses.
MORE: Here is the code with a working if/else statement to show both cases:
String = raw_input( 'Please enter a string. ')
if String[:1].isupper():
print 'The first character, ' + String[0] + ', is capitalized'
else:
print 'The first character, ' + String[0] + ', is not capitalized'
Upvotes: 1