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

相关文章

Python产生Gnuplot绘图数据的方法

Python产生Gnuplot绘图数据的方法

gnuplot的绘图可以直接选取文件绘图,文件格式要求如下: x1 y1 x2 y2 ...... xn yn 在python中利用文件操作的write方法可以非常方便实现,在此记录一...

在Python中使用NLTK库实现对词干的提取的教程

在Python中使用NLTK库实现对词干的提取的教程

什么是词干提取? 在语言形态学和信息检索里,词干提取是去除词缀得到词根的过程─—得到单词最一般的写法。对于一个词的形态词根,词干并不需要完全相同;相关的词映射到同一个词干一般能得到满意的...

python实现决策树C4.5算法详解(在ID3基础上改进)

python实现决策树C4.5算法详解(在ID3基础上改进)

一、概论 C4.5主要是在ID3的基础上改进,ID3选择(属性)树节点是选择信息增益值最大的属性作为节点。而C4.5引入了新概念“信息增益率”,C4.5是选择信息增益率最大的属性作为树节...

使用python统计文件行数示例分享

复制代码 代码如下:import time def block(file,size=65536):    while True:  &n...

Python中的FTP通信模块ftplib的用法整理

Python中默认安装的ftplib模块定义了FTP类,其中函数有限,可用来实现简单的ftp客户端,用于上传或下载文件. FTP的工作流程及基本操作可参考协议RFC959. ftp登陆连...