python获取从命令行输入数字的方法
2015-04-29 09:34
1181 查看
本文实例讲述了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获取命令行输入参数列表
- python获取命令行输入参数列表的实例代码
- Python 对输入的数字进行排序的方法
- python 循环语句while的使用——两种方法输出用户输入的数字
- Python获取shell管道数据/输入的2种方法: subprocess子进程 和 sys.stdin
- DAY2 Python 标准库 -> Getpass 模块 -> 命令行下输入密码的方法.
- java获取键盘输入的数字,并进行排序的方法
- python实现根据用户输入从电影网站获取影片信息的方法
- Python实现获取命令行输出结果的方法
- 初学python之练习将输入的数字进行排序的方法
- python实现输入数字的连续加减方法
- python基础===输入必须为数字的检验的另一种方法
- python 预设命令行变量代替raw_input 二次输入的方法
- Python之控制台输入密码的方法
- C#验证输入的是否数字的方法
- 用Python递归解决阿拉伯数字转为中文财务数字格式的问题(2)--打开思路的一种方法
- python实现定制交互式命令行的方法
- python打开文件并获取文件相关属性的方法
- Java从键盘获取输入的方法