python获取从命令行输入数字的方法

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

相关文章

Python算法应用实战之队列详解

Python算法应用实战之队列详解

队列(queue) 队列是先进先出(FIFO, First-In-First-Out)的线性表,在具体应用中通常用链表或者数组来实现,队列只允许在后端(称为rear)进行插入操作,在前端...

Python使用reportlab模块生成PDF格式的文档

(1)使用python生成pdf文档需要的最基本的包是pdfgen。它属于reportlab模块,而reportlab模块并没有默认集成到python的安装包中,所以需要安装该模块。 (...

Python提取PDF内容的方法(文本、图像、线条等)

1.安装PDFminer3k 使用pip 命令安装 pip install pdfminer3k 2.编写测试 你可以在这里获得官方参考:PDFMiner 如果你不喜欢看英...

python提取xml里面的链接源码详解

因群里朋友需要提取xml地图里面的链接,就写了这个程序。 代码: #coding=utf-8 import urllib import urllib.request import r...

pytorch 实现模型不同层设置不同的学习率方式

在目标检测的模型训练中, 我们通常都会有一个特征提取网络backbone, 例如YOLO使用的darknet SSD使用的VGG-16。 为了达到比较好的训练效果, 往往会加载预训练的b...