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操作数据库之sqlite3打开数据库、删除、修改示例
Mar 13 Python
利用QT写一个极简单的图形化Python闹钟程序
Apr 07 Python
python fabric使用笔记
May 09 Python
Python2中的raw_input() 与 input()
Jun 12 Python
Python3 socket同步通信简单示例
Jun 07 Python
django2.0扩展用户字段示例
Feb 13 Python
python实现随机漫步方法和原理
Jun 10 Python
Python入门Anaconda和Pycharm的安装和配置详解
Jul 16 Python
浅析PEP572: 海象运算符
Oct 15 Python
详解字符串在Python内部是如何省内存的
Feb 03 Python
django xadmin 管理器常用显示设置方式
Mar 11 Python
python实现定时发送邮件到指定邮箱
Dec 23 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的mssql数据库连接类实例
2014/11/28 PHP
PHP基于双向链表与排序操作实现的会员排名功能示例
2017/12/26 PHP
[HTML/CSS/Javascript]WWTJS
2007/09/25 Javascript
JavaScript获取GridView中用户点击控件的行号,列号
2009/04/14 Javascript
js 刷新页面的代码小结 推荐
2010/04/02 Javascript
菜鸟学习JavaScript小实验之函数引用
2010/11/17 Javascript
JQuery入门——用one()方法绑定事件处理函数(仅触发一次)
2013/02/05 Javascript
用js将内容复制到剪贴板兼容浏览器
2014/03/18 Javascript
js字符串完全替换函数分享
2014/12/03 Javascript
jQuery中:animated选择器用法实例
2014/12/29 Javascript
浅谈JSON中stringify 函数、toJosn函数和parse函数
2015/01/26 Javascript
JavaScript Math.round() 方法
2015/12/18 Javascript
基于JavaScript实现鼠标悬浮弹出跟随鼠标移动的带箭头的信息层
2016/01/18 Javascript
Jquery EasyUI实现treegrid上显示checkbox并取选定值的方法
2016/04/29 Javascript
jQuery基于$.ajax设置移动端click超时处理方法
2016/05/14 Javascript
jQuery插件FusionCharts绘制的3D双柱状图效果示例【附demo源码】
2017/04/20 jQuery
vue router路由嵌套不显示问题的解决方法
2017/06/17 Javascript
浅谈一个webpack构建速度优化误区
2019/06/24 Javascript
JS运算符简单用法示例
2020/01/19 Javascript
微信小程序点击按钮动态切换input的disabled禁用/启用状态功能
2020/03/07 Javascript
详解elementUI中input框无法输入的问题
2020/04/27 Javascript
Python科学计算环境推荐——Anaconda
2014/06/30 Python
详解Python中的多线程编程
2015/04/09 Python
python验证码识别的示例代码
2017/09/21 Python
python3 判断列表是一个空列表的方法
2018/05/04 Python
Python小工具之消耗系统指定大小内存的方法
2018/12/03 Python
利用python开发app实战的方法
2019/07/09 Python
python有序查找算法 二分法实例解析
2020/02/18 Python
Django后端按照日期查询的方法教程
2021/02/28 Python
html5中localStorage本地存储的简单使用
2017/06/16 HTML / CSS
美国环保婴儿用品公司:The Honest Company
2017/11/23 全球购物
英语文学专业学生的自我评价
2013/10/31 职场文书
运动会开幕式主持词
2014/03/28 职场文书
反腐倡廉演讲稿
2014/05/22 职场文书
会计专业应届生自荐信
2014/06/28 职场文书
2019银行竞聘书
2019/06/21 职场文书