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

相关文章

Numpy array数据的增、删、改、查实例

准备工作: 增、删、改、查的方法有很多很多种,这里只展示出常用的几种。 >>> import numpy as np >>> a = np.ar...

ubuntu16.04制作vim和python3的开发环境

1. 安装vim: # apt-get install  -y vim-gnome 2. 安装ctags,ctags用于支持taglist # apt-get in...

Sanic框架流式传输操作示例

本文实例讲述了Sanic框架流式传输操作。分享给大家供大家参考,具体如下: 简介 Sanic是一个类似Flask的Python 3.5+ Web服务器,它的写入速度非常快。除了Flask...

python3常用的数据清洗方法(小结)

python3常用的数据清洗方法(小结)

首先载入各种包: import pandas as pd import numpy as np from collections import Counter from sklear...

Django Form 实时从数据库中获取数据的操作方法

Django Form 实时从数据库中获取数据的操作方法

Django Form 实时从数据库中获取数据 ,具体内容如下所示: 修改 models.py 添加 class UserType(models.Model): caption =...