[Python] python获取从命令行输入的数字代码演示 →→→→→进入此内容的聊天室

来自 , 2020-08-01, 写在 Python, 查看 106 次.
URL http://www.code666.cn/view/7ac52e3f
  1. #------------------------------------------------------------------------------
  2. #           Name: numerical_input.py
  3. #         Author: Kevin Harris
  4. #  Last Modified: 02/13/04
  5. #    Description: This Python script demonstrates how to get numerical input
  6. #                 from the command line and use the if-else conditional.
  7. #------------------------------------------------------------------------------
  8.  
  9. print()
  10. print( "Welcome to the Area calculation program" )
  11. print( "---------------------------------------" )
  12. print()
  13.  
  14. # Print out the menu:
  15. print( "Please select a shape:" )
  16. print( "1  Rectangle" )
  17. print( "2  Circle" )
  18. print()
  19.  
  20. # The input function both prompts the user for input and fetches it...
  21. shape = int( input( "> " ) )
  22.  
  23. # Calculate the area...
  24. if shape == 1:
  25.     height = int( input("Please enter the height: ") )
  26.     width = int( input("Please enter the width: ") )
  27.     area = height*width
  28.     print( "The area is", area )
  29. else:
  30.     radius = int( input("Please enter the radius: ") )
  31.     area = 3.14*(radius**2)
  32.     print(  "The area is", area )
  33.  
  34. input( '\n\nPress Enter to exit...' )
  35.  
  36. #//python/8095

回复 "python获取从命令行输入的数字代码演示"

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

captcha