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 相关文章推荐
如何搜索查找并解决Django相关的问题
Jun 30 Python
Python命令行参数解析模块getopt使用实例
Apr 13 Python
详细探究Python中的字典容器
Apr 14 Python
python getopt详解及简单实例
Dec 30 Python
关于numpy中np.nonzero()函数用法的详解
Feb 07 Python
Python守护线程用法实例
Jun 23 Python
Window10+Python3.5安装opencv的教程推荐
Apr 02 Python
Python 支付整合开发包的实现
Jan 23 Python
Django 表单模型选择框如何使用分组
May 16 Python
Pytorch 抽取vgg各层并进行定制化处理的方法
Aug 20 Python
Django框架静态文件处理、中间件、上传文件操作实例详解
Feb 29 Python
详解tf.device()指定tensorflow运行的GPU或CPU设备实现
Feb 20 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
一个取得文件扩展名的函数
2006/10/09 PHP
PHP句法规则详解 入门学习
2011/11/09 PHP
php实现最简单的MVC框架实例教程
2014/09/08 PHP
php实现的简易扫雷游戏实例
2015/07/09 PHP
PHP将整数数字转换为罗马数字实例分享
2019/03/17 PHP
学习JS面向对象成果 借国庆发布个最新作品与大家交流
2009/10/03 Javascript
defer属性导致引用JQuery的页面报“浏览器无法打开网站xxx,操作被中止”错误的解决方法
2010/04/27 Javascript
jQuery 表单验证扩展代码(二)
2010/10/20 Javascript
js中的scroll和offset 使用比较的实例与分析
2013/09/29 Javascript
JS获取当前日期和时间的简单实例
2013/11/19 Javascript
setInterval与clearInterval的使用示例代码
2014/01/28 Javascript
JS+Canvas实现的俄罗斯方块游戏完整实例
2016/12/12 Javascript
简单实现Bootstrap标签页
2020/08/09 Javascript
jQuery zTree搜索-关键字查询 递归无限层功能实现代码
2018/01/25 jQuery
swiper在vue项目中loop循环轮播失效的解决方法
2018/09/15 Javascript
vue axios请求频繁时取消上一次请求的方法
2018/11/10 Javascript
实现Vue的markdown文档可以在线运行的方法示例
2018/12/11 Javascript
微信小程序设置全局请求URL及封装wx.request请求操作示例
2019/04/02 Javascript
vue router导航守卫(router.beforeEach())的使用详解
2019/04/19 Javascript
Vue动态修改网页标题的方法及遇到问题
2019/06/09 Javascript
[54:45]2018DOTA2亚洲邀请赛 4.1 小组赛 A组 Optic vs OG
2018/04/02 DOTA
浅析Python中return和finally共同挖的坑
2017/08/18 Python
zookeeper python接口实例详解
2018/01/18 Python
Python 12306抢火车票脚本
2018/02/07 Python
Python正则表达式指南 推荐
2018/10/09 Python
python实现的按要求生成手机号功能示例
2019/10/08 Python
jupyter notebook指定启动目录的方法
2021/03/02 Python
瑞士国际航空官网:SWISS
2016/07/21 全球购物
全球领先的在线cosplay服装商店:RoleCosplay
2020/01/18 全球购物
alice McCALL官网:澳大利亚时尚品牌
2020/11/16 全球购物
网络教育毕业生自我鉴定
2013/10/10 职场文书
跟单文员的岗位职责
2013/11/14 职场文书
结婚老公保证书
2015/02/26 职场文书
致我们终将逝去的青春观后感
2015/06/10 职场文书
MySQL优化常用的19种有效方法(推荐!)
2022/03/17 MySQL
Python OpenCV超详细讲解基本功能
2022/04/02 Python