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数组转置的两种实现方法

Numpy数组转置很容易,两种写法 np_array = np.array([[1, 2], [3, 4]]) np_array.transpose() np.transpose...

快速了解python leveldb

本文主要是对leveldb进行一个简单的介绍及使用Python语言对其进行操作的代码示例,具体如下。 leveldb 是google实现的一种非常高效的key-value数据库。key-...

python+openCV调用摄像头拍摄和处理图片的实现

在深度学习过程中想做手势识别相关应用,需要大量采集手势图片进行训练,作为一个懒人当然希望飞快的连续采集图片并且采集到的图片就已经被处理成统一格式的啦。。于是使用python+openCV...

解决python大批量读写.doc文件的问题

前言: java语言读写.doc的出现乱码问题: 大家都知道当我们利用java语言读写.doc文件时,无论是利用流的方式将.doc文件的内容输出到控制台(console),还是将其写到其...

简介Python中用于处理字符串的center()方法

 center()方法返回集中在长度宽度的字符串。填充是通过使用specifiedfillchar。默认填充字符是一个空格。 语法 以下是center()方法的语法: st...