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

相关文章

PyCharm汉化安装及永久激活详细教程(靠谱)

PyCharm汉化安装及永久激活详细教程(靠谱)

PyCharm 官方下载地址:http://www.jetbrains.com/pycharm/download 进入该网站后,我们会看到如下界面: professional 表示专...

python中的split()函数和os.path.split()函数使用详解

Python中有split()和os.path.split()两个函数: split():拆分字符串。通过指定分隔符对字符串进行切片,并返回分割后的字符串列表。 os.path.spli...

使用python实现对元素的长截图功能

使用python实现对元素的长截图功能

一.目标 浏览网页的时候,看见哪个元素,就能截取哪个元素当图片,不管那个元素有多长   二.所用工具和第三方库 python ,PIL,selenium pycharm 三....

python django使用haystack:全文检索的框架(实例讲解)

python django使用haystack:全文检索的框架(实例讲解)

haystack:全文检索的框架 whoosh:纯Python编写的全文搜索引擎 jieba:一款免费的中文分词包 首先安装这三个包 pip install django-haystac...

PyQtGraph在pyqt中的应用及安装过程

PyQtGraph在pyqt中的应用及安装过程

1.PyQtGraph简介: pyqtgraph的主要用途: 1、为数据、绘图、视频等提供快速、可交互图形显示。 2、提供快速开发应用的工具。 2.PyQtGraph的安装: pip i...