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

yipeiwu_com4年前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程序设计有所帮助。

相关文章

python中return的返回和执行实例

1 打印函数名和打印函数的执行过程的区别 例子1.1 def a(): print(111) print(a) # 打印a函数的内存地址,不会对a函数有影响,a函数不会执行 pr...

Django视图之ORM数据库查询操作API的实例

查询表记录 查询相关API 操作:models.表名.objects.方法() <BR>all(): 查询所有结果 filter(**kwargs): 它...

对python csv模块配置分隔符和引用符详解

如下所示: file = open('./abc.csv') csv.reader(file, delimiter=',', quotechar='"') 说明:delimiter...

Python + OpenCV 实现LBP特征提取的示例代码

Python + OpenCV 实现LBP特征提取的示例代码

背景 看了些许的纹理特征提取的paper,想自己实现其中部分算法,看看特征提取之后的效果是怎样 运行环境 Mac OS Python3.0 Anaconda3(集成了很多包...

全面解析Python的While循环语句的使用方法

全面解析Python的While循环语句的使用方法

Python 编程中 while 语句用于循环执行程序,即在某条件下,循环执行某段程序,以处理需要重复处理的相同任务。其基本形式为: while 判断条件: 执行语句……...