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程序设计有所帮助。

相关文章

Python三级目录展示的实现方法

Python三级目录展示的实现方法

要求: 1、三级菜单 2、可依次选择进入各子菜单,选择序号进入目录 3、输入b返回上级目录,q退出更改目录 代码实现: #!/bin/env python #!--*--co...

python使用 request 发送表单数据操作示例

python使用 request 发送表单数据操作示例

本文实例讲述了python使用 request 发送表单数据操作。分享给大家供大家参考,具体如下: # !/usr/bin/env python # -*- coding: utf-...

对Xpath 获取子标签下所有文本的方法详解

对Xpath 获取子标签下所有文本的方法详解

在爬虫中遇见这种怎么办 想提取名称, 但是 名称不在一个标签里 使用xpath string()方法 例如 data.xpath("string(path)") path --...

python 删除列表里所有空格项的方法总结

python 删除列表里所有空格项的方法总结

首先,我们来随便写一个带空格的列表: list1 = ['122','2333','3444',' ','422',' ',' ','54',' '] 相信已经有人尝试过,诸如以下...

python 自定义异常和异常捕捉的方法

异常捕捉: try: XXXXX1 raise Exception(“xxxxx2”) except (Exception1,Exception2,……): xxxx3...