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 相关文章推荐
Python3.2中Print函数用法实例详解
May 19 Python
wxPython定时器wx.Timer简单应用实例
Jun 03 Python
Python Sql数据库增删改查操作简单封装
Apr 18 Python
Python处理Excel文件实例代码
Jun 20 Python
python模拟事件触发机制详解
Jan 19 Python
PyQt实现界面翻转切换效果
Apr 20 Python
Python3.6简单的操作Mysql数据库的三个实例
Oct 17 Python
[原创]Python入门教程5. 字典基本操作【定义、运算、常用函数】
Nov 01 Python
Python发送邮件功能示例【使用QQ邮箱】
Dec 04 Python
python正则表达式去除两个特殊字符间的内容方法
Dec 24 Python
python实现微信小程序用户登录、模板推送
Aug 28 Python
如何正确理解python装饰器
Jun 15 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自定义函数收代码
2010/08/01 PHP
PHP与SQL注入攻击防范小技巧
2011/09/16 PHP
PHP 中检查或过滤IP地址的实现代码
2011/11/27 PHP
PHP多维数组转一维数组的简单实现方法
2015/12/23 PHP
PHP数组操作简单案例分析
2016/10/15 PHP
详解PHP中的外观模式facade pattern
2018/02/05 PHP
jquery 选择器部分整理
2009/10/28 Javascript
jQuery实现鼠标滑过Div层背景变颜色的方法
2015/02/17 Javascript
JavaScript里四舍五入函数round用法实例
2015/04/06 Javascript
js阻止浏览器默认行为触发的通用方法(推荐)
2016/05/15 Javascript
jQuery获取单击节点对象的方法
2016/06/02 Javascript
JS实现的多张图片轮流播放幻灯片效果
2016/07/22 Javascript
NodeJS仿WebApi路由示例
2017/02/28 NodeJs
Angular事件之不同组件间传递数据的方法
2018/11/15 Javascript
vue生命周期与钩子函数简单示例
2019/03/13 Javascript
[03:40]DOTA2英雄梦之声_第01期_炼金术士
2014/06/23 DOTA
Python科学画图代码分享
2017/11/29 Python
Python编程使用tkinter模块实现计算器软件完整代码示例
2017/11/29 Python
python学生管理系统学习笔记
2019/03/19 Python
python Jupyter运行时间实例过程解析
2019/12/13 Python
python 装饰器的实际作用有哪些
2020/09/07 Python
使用HTML5的Canvas绘制曲线的简单方法
2015/09/08 HTML / CSS
台湾百利市购物中心:e-Payless
2017/08/16 全球购物
Booking.com西班牙:全球酒店预订
2018/03/30 全球购物
Sneaker Studio法国:购买运动鞋
2018/06/08 全球购物
采用冷却技术的超自然舒适度:GhostBed床垫
2018/09/18 全球购物
植村秀美国官网:Shu Uemura美国
2019/03/19 全球购物
关于礼仪的演讲稿
2014/01/04 职场文书
大学旷课检讨书
2014/01/28 职场文书
物流管理毕业生自荐信范文
2014/03/15 职场文书
小学毕业演讲稿
2014/04/25 职场文书
课前一分钟演讲稿
2014/08/26 职场文书
债务纠纷委托书
2014/08/30 职场文书
浅谈Nginx 中的两种限流方式
2021/03/31 Servers
Mysql 如何实现多张无关联表查询数据并分页
2021/06/05 MySQL
NASA 机智号火星直升机拍到了毅力号设备碎片
2022/04/29 数码科技