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

相关文章

Python3.5 Json与pickle实现数据序列化与反序列化操作示例

Python3.5 Json与pickle实现数据序列化与反序列化操作示例

本文实例讲述了Python3.5 Json与pickle实现数据序列化与反序列化操作。分享给大家供大家参考,具体如下: 1、Json:不同语言之间进行数据交互。 (1)JSON数据序列化...

python实现基于朴素贝叶斯的垃圾分类算法

python实现基于朴素贝叶斯的垃圾分类算法

一、模型方法        本工程采用的模型方法为朴素贝叶斯分类算法,它的核心算法思想基于概率论。我们称之为“朴素”,是因为整个形式化过程只做最原...

10分钟教你用python动画演示深度优先算法搜寻逃出迷宫的路径

10分钟教你用python动画演示深度优先算法搜寻逃出迷宫的路径

深度优先算法(DFS 算法)是什么? 寻找起始节点与目标节点之间路径的算法,常用于搜索逃出迷宫的路径。主要思想是,从入口开始,依次搜寻周围可能的节点坐标,但不会重复经过同一个节点,且不能...

详解django三种文件下载方式

一、概述 在实际的项目中很多时候需要用到下载功能,如导excel、pdf或者文件下载,当然你可以使用web服务自己搭建可以用于下载的资源服务器,如nginx,这里我们主要介绍djang...

python 反向输出字符串的方法

python 反向输出字符串的方法 方法一:采用列表reversed函数 class Solution(object): def reverse_string(self, s):...