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正则表达式抓取成语网站
Nov 20 Python
Python编程中运用闭包时所需要注意的一些地方
May 02 Python
使用NumPy和pandas对CSV文件进行写操作的实例
Jun 14 Python
解决python3.5 正常安装 却不能直接使用Tkinter包的问题
Feb 22 Python
详解python读取和输出到txt
Mar 29 Python
python画图--输出指定像素点的颜色值方法
Jul 03 Python
python不相等的两个字符串的 if 条件判断为True详解
Mar 12 Python
python安装和pycharm环境搭建设置方法
May 27 Python
pycharm软件实现设置自动保存操作
Jun 08 Python
python连接mysql有哪些方法
Jun 24 Python
Python数据结构之队列详解
Mar 21 Python
Python 视频画质增强
Apr 28 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 二维数组根据某个字段排序的具体实现
2014/06/03 PHP
PHP定时任务延缓执行的实现
2014/10/08 PHP
PHP大转盘中奖概率算法实例
2014/10/21 PHP
将PHP程序中返回的JSON格式数据用gzip压缩输出的方法
2016/03/03 PHP
PHP生成随机数的方法总结
2018/03/01 PHP
PHP实现的62进制转10进制,10进制转62进制函数示例
2019/06/06 PHP
php实现JWT(json web token)鉴权实例详解
2019/11/05 PHP
jquery ajax对特殊字符进行转义防止js注入使用示例
2013/11/21 Javascript
jqplot通过ajax动态画折线图的方法及思路
2013/12/08 Javascript
js定时器(执行一次、重复执行)
2014/03/07 Javascript
document.addEventListener使用介绍
2014/03/07 Javascript
javascript中键盘事件用法实例分析
2015/01/30 Javascript
js实现温度计时间样式代码分享
2015/08/21 Javascript
Js自定义多选框效果的实例代码
2017/07/05 Javascript
arcgis for js栅格图层叠加(Raster Layer)问题
2017/11/22 Javascript
Vue.js 2.0和Cordova开发webApp环境搭建方法
2018/02/26 Javascript
解决angularjs前后端分离调用接口传递中文时中文乱码的问题
2018/08/13 Javascript
node获取客户端ip功能简单示例
2019/08/24 Javascript
[01:10:58]Spirit vs NB Supermajor小组赛 A组败者组决赛 BO3 第二场 6.2
2018/06/03 DOTA
浅谈django model的get和filter方法的区别(必看篇)
2017/05/23 Python
python字符串替换第一个字符串的方法
2019/06/26 Python
以SQLite和PySqlite为例来学习Python DB API
2020/02/05 Python
Matplotlib使用Cursor实现UI定位的示例代码
2020/03/12 Python
简单了解python shutil模块原理及使用方法
2020/04/28 Python
css3的过滤效果简单实例
2016/08/03 HTML / CSS
HTML5 Blob对象的具体使用
2020/05/22 HTML / CSS
英国领先的男士美容护发用品公司:Mankind
2016/08/31 全球购物
乡镇信息公开实施方案
2014/03/23 职场文书
优秀应届生求职信
2014/06/16 职场文书
2014年仓库管理工作总结
2014/12/17 职场文书
邮政营业员岗位职责
2015/04/14 职场文书
电视新闻稿
2015/07/17 职场文书
男方家长婚礼致辞
2015/07/27 职场文书
2016大学生毕业实习心得体会
2016/01/23 职场文书
python基础学习之递归函数知识总结
2021/05/26 Python
详解Python描述符的工作原理
2021/06/11 Python