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

相关文章

Flask框架实现的前端RSA加密与后端Python解密功能详解

Flask框架实现的前端RSA加密与后端Python解密功能详解

本文实例讲述了Flask框架实现的前端RSA加密与后端Python解密功能。分享给大家供大家参考,具体如下: 前言 在使用 Flask 开发用户登录API的时候,我之前都是明文传输 us...

Python中异常重试的解决方案详解

前言 大家在做数据抓取的时候,经常遇到由于网络问题导致的程序保存,先前只是记录了错误内容,并对错误内容进行后期处理。 原先的流程: def crawl_page(url): pa...

Python中的rjust()方法使用详解

 rjust()该方法返回字符串合理字符串的右边的长度宽度。填充是通过使用指定的fillchar(默认为空格)。如果宽度小于len(s)返回原始字符串。 语法 以下是rjust...

python实现定制交互式命令行的方法

Python的交互式命令行可通过启动文件来配置。 当Python启动时,会查找环境变量PYTHONSTARTUP,并且执行该变量中所指定文件里的程序代码。该指定文件名称以及地址可以是随意...

使用Python实现正态分布、正态分布采样

使用Python实现正态分布、正态分布采样

多元正态分布(多元高斯分布) 直接从多元正态分布讲起。多元正态分布公式如下: 这就是多元正态分布的定义,均值好理解,就是高斯分布的概率分布值最大的位置,进行采样时也就是采样的中心点。而...