[Python] python if else语句使用演示 →→→→→进入此内容的聊天室

来自 , 2020-12-30, 写在 Python, 查看 106 次.
URL http://www.code666.cn/view/4c92d46d
  1. #------------------------------------------------------------------------------
  2. #           Name: if_conditional.py
  3. #         Author: Kevin Harris
  4. #  Last Modified: 02/13/04
  5. #    Description: This Python script demonstrates how to use if-else
  6. #                 conditionals.
  7. #------------------------------------------------------------------------------
  8.  
  9. # Our first example is a simple if/else statement
  10.  
  11. print( "Please enter a negative number" )
  12.  
  13. number = int( input( "> " ) )
  14.  
  15. if number >= 0:
  16.     print( "That wasn't negative!" )
  17. else:
  18.     print( "Thank you!" )
  19.  
  20. # Our next example is a simple if/else if/else statement
  21.  
  22. print( "Which type of pet do you prefer?" )
  23. print( " cats" )
  24. print( " dogs" )
  25.  
  26. # Note how we use raw_input to get the input as a string
  27. pet = input( "> " )
  28.  
  29. if pet == "cats":
  30.     print( "You chose cats." )
  31. elif pet == "dogs":
  32.     print( "You chose dogs." )
  33. else:
  34.     print( "That's not one of the choices." )
  35.  
  36. input( '\n\nPress Enter to exit...' )
  37.  
  38. #//python/8093

回复 "python if else语句使用演示"

这儿你可以回复上面这条便签

captcha