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代码的打包与发布详解
Jul 30 Python
python使用装饰器和线程限制函数执行时间的方法
Apr 18 Python
Python3控制路由器——使用requests重启极路由.py
May 11 Python
python django 实现验证码的功能实例代码
May 18 Python
Python3调用微信企业号API发送文本消息代码示例
Nov 10 Python
Python cookbook(数据结构与算法)从字典中提取子集的方法示例
Mar 22 Python
python爬取足球直播吧五大联赛积分榜
Jun 13 Python
python应用文件读取与登录注册功能
Sep 23 Python
python将四元数变换为旋转矩阵的实例
Dec 04 Python
Django基于客户端下载文件实现方法
Apr 21 Python
利用python如何实现猫捉老鼠小游戏
Dec 04 Python
Python实战实现爬取天气数据并完成可视化分析详解
Jun 16 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后门URL的防范
2013/11/12 PHP
PHP获取QQ达人QQ信息的方法
2015/03/05 PHP
PHP编程实现计算抽奖概率算法完整实例
2017/08/09 PHP
laravel入门知识点整理
2020/09/15 PHP
一个js拖拽的效果类和dom-drag.js浅析
2010/07/17 Javascript
基于jQuery的图片左右无缝滚动插件
2012/05/23 Javascript
原生js实现跨浏览器获取鼠标按键的值
2013/04/08 Javascript
JavaScript中判断整字类型最简洁的实现方法
2014/11/08 Javascript
javascript中typeof操作符和constucor属性检测
2015/02/26 Javascript
Jquery动态添加输入框的方法
2015/05/29 Javascript
JQuery实现鼠标移动图片显示描述层的方法
2015/06/25 Javascript
基于jquery实现鼠标滚轮驱动的图片切换效果
2015/10/26 Javascript
关于AngularJs数据的本地存储详解
2017/01/20 Javascript
COM组件中调用JavaScript函数详解及实例
2017/02/23 Javascript
使用angular-cli webpack创建多个包的方法
2018/10/16 Javascript
深入理解Puppeteer的入门教程和实践
2019/03/05 Javascript
js+html实现点名系统功能
2019/11/05 Javascript
js实现无缝轮播图
2020/03/09 Javascript
深入webpack打包原理及loader和plugin的实现
2020/05/06 Javascript
Python中使用item()方法遍历字典的例子
2014/08/26 Python
opencv python 基于KNN的手写体识别的实例
2018/08/03 Python
Python3 搭建Qt5 环境的方法示例
2020/07/16 Python
pandas使用函数批量处理数据(map、apply、applymap)
2020/11/27 Python
CSS3中Transform动画属性用法详解
2016/07/04 HTML / CSS
CSS3 Pie工具推荐--让IE6-8支持一些优秀的CSS3特性
2014/09/02 HTML / CSS
美国知名户外用品畅销中心:Sierra Trading Post
2016/07/19 全球购物
牦牛毛户外探险服装:Kora
2019/02/08 全球购物
澳大利亚运动鞋商店:Platypus Shoes
2019/09/27 全球购物
路由表示做什么用的?在linux环境中怎么来配置一条默认路由?
2013/06/07 面试题
商务英语求职自荐信范文
2013/12/24 职场文书
上课打牌的检讨书
2014/02/15 职场文书
纪念一二九运动演讲稿
2014/09/16 职场文书
部队个人年终总结
2015/03/02 职场文书
2015年教师节贺卡寄语
2015/03/24 职场文书
《酸的和甜的》教学反思
2016/02/18 职场文书
解决ubuntu安装软件时,status-code=409报错的问题
2022/12/24 Servers