python 2.7.6 isupper function in if/elif/else statements

前端 未结 1 1396
借酒劲吻你
借酒劲吻你 2021-01-28 07:33

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         


        
相关标签:
1条回答
  • 2021-01-28 08:09

    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'
    
    0 讨论(0)
提交回复
热议问题