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

相关文章

对变量赋值的理解--Pyton中让两个值互换的实现方法

#Pyton中让两个值互换的实现方法 #方法一:可以理解为相当于是同时赋值 a = 5 b = 4 a,b = b,a print(a,b) #方法二:可以理解为拿箱子过程 c...

Python使用numpy产生正态分布随机数的向量或矩阵操作示例

Python使用numpy产生正态分布随机数的向量或矩阵操作示例

本文实例讲述了Python使用numpy产生正态分布随机数的向量或矩阵操作。分享给大家供大家参考,具体如下: 简单来说,正态分布(Normal distribution)又名高斯分布(G...

Python编译为二进制so可执行文件实例

通过cpython把python的文件转换为二进制文件,达到代码保护的目的 1、下载Cython-0.28.2.tar.gz python setup.py install安装 2、创...

python读取Excel表格文件的方法

python读取Excel表格文件的方法

python读取Excel表格文件,例如获取这个文件的数据 python读取Excel表格文件,需要如下步骤: 1、安装Excel读取数据的库-----xlrd 直接pip insta...

Python绘制热力图示例

Python绘制热力图示例

本文实例讲述了Python绘制热力图操作。分享给大家供大家参考,具体如下: 示例一: # -*- coding: utf-8 -*- from pyheatmap.heatmap i...