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内置模块collections

collections是Python内建的一个集合模块,提供了许多有用的集合类。 1、namedtuple python提供了很多非常好用的基本类型,比如不可变类型tuple,我们可以轻...

python+VTK环境搭建及第一个简单程序代码

python+VTK环境搭建及第一个简单程序代码

简介: Vtk,(visualization toolkit)是一个开源的免费软件系统,主要用于三维计算机图形学、图像处理和可视化。Vtk是在面向对象原理的基础上设计和实现的,它的内核是...

总结用Pdb库调试Python的方式及常用的命令

用Pdb调试有多种方式 使用 Pdb调试 Python的程序的方式主要是下面的三种!下面逐一介绍 命令行加-m参数 命令行启动目标程序,加上-m参数,这样调用 testPdb.py的...

Python 访问限制 private public的详细介绍

 一、知识点 在一个模块中,我们可能会定义很多函数和变量。但有的函数和变量我们希望能给别人使用,有的函数和变量我们希望仅仅在模块内部使用,so? 我们可以通过定义该函...

python实现批量修改文件名代码

python实现批量修改文件名代码

我曾以为,写脚本是很难的,直到我遇到了Python 前言随着国内版权意识的跟进,很多影视音乐资源开始收费,而且度盘又经常随意封杀各种资源,所以,为了保护资源,老司机们越来越倾向于把资源下...