python获取从命令行输入数字的方法

yipeiwu_com6年前Python基础

本文实例讲述了python获取从命令行输入数字的方法。分享给大家供大家参考。具体如下:

#----------------------------------------
#      Name: numerical_input.py
#     Author: Kevin Harris
# Last Modified: 02/13/04
#  Description: This Python script demonstrates 
#         how to get numerical input
#         from the command line 
#         and use the if-else conditional.
#----------------------------------------
print()
print( "Welcome to the Area calculation program" )
print( "---------------------------------------" )
print()
# Print out the menu:
print( "Please select a shape:" )
print( "1 Rectangle" )
print( "2 Circle" )
print()
# The input function both prompts the user
# for input and fetches it...
shape = int( input( "> " ) )
# Calculate the area...
if shape == 1:
  height = int( input("Please enter the height: ") )
  width = int( input("Please enter the width: ") )
  area = height*width
  print( "The area is", area )
else:
  radius = int( input("Please enter the radius: ") )
  area = 3.14*(radius**2)
  print( "The area is", area )
input( '\n\nPress Enter to exit...' )

希望本文所述对大家的Python程序设计有所帮助。

相关文章

浅谈pandas筛选出表中满足另一个表所有条件的数据方法

浅谈pandas筛选出表中满足另一个表所有条件的数据方法

今天记录一下pandas筛选出一个表中满足另一个表中所有条件的数据。例如: list1 结构:名字,ID,颜色,数量,类型。 list1 = [['a',1,255,100,'03'],...

Python数据类型中的“冒号“[::]——分片与步长操作示例

Python数据类型中的“冒号“[::]——分片与步长操作示例

本文实例讲述了Python数据类型中的“冒号“[::]——分片与步长操作。分享给大家供大家参考,具体如下: 例如有如下字符串: string = "welcome to jb51^_...

Python输出PowerPoint(ppt)文件中全部文字信息的方法

本文实例讲述了Python输出PowerPoint(ppt)文件中全部文字信息的方法。分享给大家供大家参考。具体分析如下: 下面的代码依赖于windows com,所以必须在机器上安装P...

python程序封装为win32服务的方法

本文实例为大家分享了python程序封装为win32服务的具体代码,供大家参考,具体内容如下 # encoding=utf-8 import os import sys import...

Python中 CSV格式清洗与转换的实例代码

题目: CSV格式清洗与转换 描述 附件是一个CSV格式文件,提取数据进行如下格式转换:‪‬‪‬‪‬‪...