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使用matplotlib实现在坐标系中画一个矩形的方法
May 20 Python
Python出现segfault错误解决方法
Apr 16 Python
python3+PyQt5 创建多线程网络应用-TCP客户端和TCP服务器实例
Jun 17 Python
Python 寻找局部最高点的实现
Dec 05 Python
Python小整数对象池和字符串intern实例解析
Mar 21 Python
python中pow函数用法及功能说明
Dec 04 Python
Python爬虫新手入门之初学lxml库
Dec 20 Python
Python+kivy BoxLayout布局示例代码详解
Dec 28 Python
Python入门基础之数字字符串与列表
Feb 01 Python
python Polars库的使用简介
Apr 21 Python
Python机器学习之底层实现KNN
Jun 20 Python
图神经网络GNN算法
May 11 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设计模式 php实现门面模式(Facade)
2015/12/07 PHP
php生成无限栏目树
2017/03/16 PHP
Javascript 命名空间模式
2013/11/01 Javascript
浅析XMLHttpRequest的缓存问题
2013/12/13 Javascript
jQuery实现带滚动导航效果的全屏滚动相册实例
2015/06/19 Javascript
Bootstrap每天必学之媒体对象
2015/11/30 Javascript
javascript执行环境及作用域详解
2016/05/05 Javascript
Ext JS动态加载JavaScript创建窗体的方法
2016/06/23 Javascript
AngularJS实现根据变量改变动态加载模板的方法
2016/11/04 Javascript
jQuery扩展_动力节点Java学院整理
2017/07/05 jQuery
vue.js element-ui tree树形控件改iview的方法
2018/03/29 Javascript
解决vue-router在同一个路由下切换,取不到变化的路由参数问题
2018/09/01 Javascript
JS浮点数运算结果不精确的Bug解决
2019/08/01 Javascript
原生javascript的ajax请求及后台PHP响应操作示例
2020/02/24 Javascript
javascript解析json格式的数据方法详解
2020/08/07 Javascript
JavaScript实现H5接金币功能(实例代码)
2021/02/22 Javascript
详解python基础之while循环及if判断
2017/08/24 Python
pandas 层次化索引的实现方法
2019/07/06 Python
Python 在OpenCV里实现仿射变换—坐标变换效果
2019/08/30 Python
CSS教程:CSS3圆角属性
2009/04/02 HTML / CSS
加拿大花店:1800Flowers.ca
2016/11/16 全球购物
具有防紫外线功能的高性能钓鱼服装:Hook&Tackle
2018/08/16 全球购物
Tomcat中怎么使用log4j输出所有的log
2016/07/07 面试题
数控技术应届生求职信
2013/11/13 职场文书
大学生怎样进行自我评价
2013/12/07 职场文书
通信研究生自荐信
2014/02/01 职场文书
数控个人求职信范文
2014/02/03 职场文书
党员大会主持词
2014/04/02 职场文书
聘用意向书
2014/07/29 职场文书
文员转正自我鉴定怎么写
2014/09/29 职场文书
本科毕业论文导师评语
2014/12/31 职场文书
表扬通报怎么写
2015/01/16 职场文书
创先争优承诺书
2015/01/20 职场文书
环卫处个人工作总结
2015/03/04 职场文书
建筑技术负责人岗位职责
2015/04/13 职场文书
多属性、多分类MySQL模式设计
2021/04/05 MySQL