python获取从命令行输入数字的方法

yipeiwu_com6年前Python基础

本文实例讲述了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程序设计有所帮助。

相关文章

django 自定义filter 判断if var in list的例子

1. 需求: 用户答题练习,当用户获取所有题目的同时,需要判断用户是否已经做过该题目,如果做过,需要render的时候添加一个“回顾”按钮。 2. 实现 a. 查询用户做过题目的id...

python计算无向图节点度的实例代码

python计算无向图节点度的实例代码

废话不多说了,直接上代码吧: #Copyright (c)2017, 东北大学软件学院学生 # All rightsreserved #文件名称:a.py # 作 者:孔云 #问题...

python实现自动登录后台管理系统

python实现自动登录后台管理系统

本文实例为大家分享了python实现自动登录后台管理系统的具体代码,供大家参考,具体内容如下 首先感谢下网络上的各位大神和博主,通过学习各位大神的文章,才实现了该脚本 ①首先浏览器运行真...

Django的分页器实例(paginator)

先导入模块: from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger 分页器paginat...

php使用递归与迭代实现快速排序示例

复制代码 代码如下:/** * 递归法实现的快速排序 * @param $seq * @return array */function quick...