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

yipeiwu_com5年前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中py文件引用另一个py文件变量的方法

最近自己初学Python,在编程是遇到一个问题就是,怎样在一个py文件中使用另一个py文件中变量,问题如下: demo1代码 import requests r = requests...

Python中特殊函数集锦

Python中特殊函数集锦

以下内容主要针过滤函数filter , 映射和归并函数map/reduce , 装饰器@ 以及 匿名函数lamda,具体内容如下: 1. 过滤函数filte...

Python入门篇之数字

Python入门篇之数字

数字类型   数字提供了标量贮存和直接访问。它是不可更改类型,也就是说变更数字的值会生成新的对象。当然,这个过程无论对程序员还是对用户都是透明的,并不会影响软件的开发方式。 P...

使用python制作一个解压缩软件

使用python制作一个解压缩软件

python实现解压缩的重要模块就是——zipfile,其次是os 安装zipfile模块 首先得安装zipfile模块,打开cmd输入一下命令即可安装 pip install zipf...

解决Python pandas plot输出图形中显示中文乱码问题

解决方式一: import matplotlib #1. 获取matplotlibrc文件所在路径 matplotlib.matplotlib_fname() #Out[3]: u'...