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


Posted in Python onApril 29, 2015

本文实例讲述了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 相关文章推荐
python 生成目录树及显示文件大小的代码
Jul 23 Python
Python判断变量是否已经定义的方法
Aug 18 Python
python使用装饰器和线程限制函数执行时间的方法
Apr 18 Python
python生成器generator用法实例分析
Jun 04 Python
python从入门到精通(DAY 1)
Dec 20 Python
基于python实现KNN分类算法
Apr 23 Python
Python + Flask 实现简单的验证码系统
Oct 01 Python
python循环嵌套的多种使用方法解析
Nov 29 Python
Python将列表中的元素转化为数字并排序的示例
Dec 25 Python
Python xlrd excel文件操作代码实例
Mar 10 Python
手把手教你如何用Pycharm2020.1.1配置远程连接的详细步骤
Aug 07 Python
python模拟点击在ios中实现的实例讲解
Nov 26 Python
在Python中处理XML的教程
Apr 29 #Python
python搜索指定目录的方法
Apr 29 #Python
python中sleep函数用法实例分析
Apr 29 #Python
介绍Python中内置的itertools模块
Apr 29 #Python
python使用fileinput模块实现逐行读取文件的方法
Apr 29 #Python
python将字符串转换成数组的方法
Apr 29 #Python
Python中使用hashlib模块处理算法的教程
Apr 28 #Python
You might like
php 删除记录实现代码
2009/03/12 PHP
php做下载文件的实现代码及文件名中乱码解决方法
2011/02/03 PHP
php引用传值实例详解学习
2013/11/06 PHP
php命令行使用方法和命令行参数说明
2014/04/08 PHP
JS控制一个DIV层在指定时间内消失的方法
2014/02/17 Javascript
javascript关于运动的各种问题经典总结
2015/04/27 Javascript
js简单实现竖向tab选项卡的方法
2015/05/04 Javascript
Backbone.js的一些使用技巧
2015/07/01 Javascript
JS实现统计复选框选中个数并提示确定与取消的方法
2015/07/01 Javascript
jQuery基于cookie实现的购物车实例分析
2015/12/24 Javascript
layui表格实现代码
2017/05/20 Javascript
axios向后台传递数组作为参数的方法
2018/08/11 Javascript
从零学python系列之新版本导入httplib模块报ImportError解决方案
2014/05/23 Python
在Linux中通过Python脚本访问mdb数据库的方法
2015/05/06 Python
关于Django外键赋值问题详解
2017/08/13 Python
python 寻找优化使成本函数最小的最优解的方法
2017/12/28 Python
Python获取当前函数名称方法实例分享
2018/01/18 Python
wxPython+Matplotlib绘制折线图表
2019/11/19 Python
python函数不定长参数使用方法解析
2019/12/14 Python
python读取图片的几种方式及图像宽和高的存储顺序
2020/02/11 Python
Python selenium键盘鼠标事件实现过程详解
2020/07/28 Python
css3新增颜色表示方式分享
2014/04/15 HTML / CSS
css3动画 小球滚动 js控制动画暂停
2019/11/29 HTML / CSS
AC Lens:购买隐形眼镜
2017/02/26 全球购物
The North Face北面英国官网:美国著名户外品牌
2017/12/13 全球购物
Godiva巧克力英国官网:比利时歌帝梵巧克力
2018/08/28 全球购物
项目经理的岗位职责
2013/11/23 职场文书
会计出纳岗位职责
2013/12/25 职场文书
社保委托书怎么写
2014/08/02 职场文书
2014年学校财务工作总结
2014/12/06 职场文书
2015羊年春节慰问信
2015/02/14 职场文书
家装业务员岗位职责
2015/04/03 职场文书
开场白怎么写
2015/06/01 职场文书
2016年教师学习教师法心得体会
2016/01/20 职场文书
使用pandas生成/读取csv文件的方法实例
2021/07/09 Python
Javascript webpack动态import
2022/04/19 Javascript