美文网首页
python if else语句使用演示的代码

python if else语句使用演示的代码

作者: ahtia | 来源:发表于2020-06-10 11:03 被阅读0次

    如下的资料是关于python if else语句使用演示的代码,应该对小伙伴们有较大帮助。

    #------------------------------------------------------------------------------

    #          Name: if_conditional.py

    #        Author: Kevin Harris

    #  Last Modified: 02/13/04

    #    Description: This Python script demonstrates how to use if-else

    #                conditionals.

    #------------------------------------------------------------------------------

    # Our first example is a simple if/else statement

    print( "Please enter a negative number" )

    number = int( input( "> " ) )

    if number >= 0:

        print( "That wasn't negative!" )

    else:

        print( "Thank you!" )

    # Our next example is a simple if/else if/else statement

    print( "Which type of pet do you prefer?" )

    print( " cats" )

    print( " dogs" )

    # Note how we use raw_input to get the input as a string

    pet = input( "> " )

    if pet == "cats":

        print( "You chose cats." )

    elif pet == "dogs":

        print( "You chose dogs." )

    else:

        print( "That's not one of the choices." )

    input( 'nnPress Enter to exit...' )

    相关文章

      网友评论

          本文标题:python if else语句使用演示的代码

          本文链接:https://www.haomeiwen.com/subject/egputktx.html