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远程桌面协议RDPY安装使用介绍
Apr 15 Python
Python list操作用法总结
Nov 10 Python
详解Python map函数及Python map()函数的用法
Nov 16 Python
python中列表和元组的区别
Dec 18 Python
用Python一键搭建Http服务器的方法
Jun 01 Python
python使用PIL实现多张图片垂直合并
Jan 15 Python
python numpy 按行归一化的实例
Jan 21 Python
树莓派使用USB摄像头和motion实现监控
Jun 22 Python
matplotlib quiver箭图绘制案例
Apr 17 Python
python 串行执行和并行执行实例
Apr 30 Python
浅谈如何使用python抓取网页中的动态数据实现
Aug 17 Python
python3环境搭建过程(利用Anaconda+pycharm)完整版
Aug 19 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 expects parameter 1 to be resource, array given 错误
2011/03/23 PHP
php文件操作实例代码
2012/05/10 PHP
php和js如何通过json互相传递数据相关问题探讨
2013/02/26 PHP
php 生成唯一id的几种解决方法
2013/03/08 PHP
PHP不用递归遍历目录下所有文件的代码
2014/07/04 PHP
php购物车实现方法
2015/01/03 PHP
PHP多线程之内部多线程实例分析
2015/03/09 PHP
php数组转成json格式的方法
2015/03/09 PHP
php函数mkdir实现递归创建层级目录
2016/10/27 PHP
浅谈PHP中new self()和new static()的区别
2017/08/11 PHP
模仿jQuery each函数的链式调用
2009/07/22 Javascript
innerText和textContent对比及使用介绍
2013/02/27 Javascript
通过一段代码简单说js中的this的使用
2013/07/23 Javascript
jquery ajax post提交数据乱码
2013/11/05 Javascript
javascript 拷贝节点cloneNode()使用介绍
2014/04/03 Javascript
AngularJS初始化过程分析(引导程序)
2014/12/06 Javascript
理解javascript模块化
2016/03/28 Javascript
Vue 递归多级菜单的实例代码
2019/05/05 Javascript
vue实现日历表格(element-ui)
2020/09/24 Javascript
[57:29]Alliance vs KG 2019国际邀请赛小组赛 BO2 第二场 8.16
2019/08/17 DOTA
c++生成dll使用python调用dll的方法
2014/01/20 Python
用Python编写生成树状结构的文件目录的脚本的教程
2015/05/04 Python
详解JavaScript编程中的window与window.screen对象
2015/10/26 Python
python网络编程调用recv函数完整接收数据的三种方法
2017/03/31 Python
PyCharm永久激活方式(推荐)
2020/09/22 Python
Django项目在pycharm新建的步骤方法
2021/03/02 Python
CSS3+Sprite实现僵尸行走动画特效源码
2016/01/27 HTML / CSS
Skip Hop官网:好莱坞宝宝挚爱品牌
2018/06/17 全球购物
亚洲颇具影响力的男性在线购物零售商:His
2019/11/24 全球购物
工作过失检讨书
2014/02/23 职场文书
《明天,我们毕业》教学反思
2014/04/24 职场文书
个人查摆问题及整改措施
2014/10/16 职场文书
高中生思想道德自我评价
2015/03/09 职场文书
物业工程部经理岗位职责
2015/04/09 职场文书
六一晚会主持词开场白
2015/05/28 职场文书
Vue3 Composition API的使用简介
2021/03/29 Vue.js