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实现公众号每日定时发送日报和图片

python3实现公众号每日定时发送日报和图片

本文实例为大家分享了python3实现公众号每日定时发送的具体代码,供大家参考,具体内容如下 步骤是这样:先申请公众号,找到接口文件。看了之后发现主要是通过corpid(企业秘钥)和co...

Python基于socket模块实现UDP通信功能示例

Python基于socket模块实现UDP通信功能示例

本文实例讲述了Python基于socket模块实现UDP通信功能。分享给大家供大家参考,具体如下: 一 代码 1、接收端 import socket #使用IPV4协议,使用UDP协...

基于python 字符编码的理解

一、字符编码简史: 美国:1963年 ASCII (包含127个字符  占1个字节) 中国:1980年 GB2312 (收录7445个汉字,包括6763个汉字和682个其它符号...

python中scikit-learn机器代码实例

我们给大家带来了关于学习python中scikit-learn机器代码的相关具体实例,以下就是全部代码内容: # -*- coding: utf-8 -*- import num...

python实现web方式logview的方法

本文实例讲述了python实现web方式logview的方法。分享给大家供大家参考。具体如下: 这里用Python实现web方式查看日志的一个小东西,使用python的popen执行了l...