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

相关文章

python中类的属性和方法介绍

Python-类属性,实例属性,类方法,静态方法,实例方法 类属性和实例属性 #coding:utf-8 class Student(object): name = 'I am...

python 3.6.7实现端口扫描器

本文实例为大家分享了python 3.6.7端口扫描器的具体代码,供大家参考,具体内容如下 环境:python 3.6.7 # -*- coding: utf-8 -*- impor...

Python把csv数据写入list和字典类型的变量脚本方法

如下所示: #coding=utf8 import csv import logging logging.basicConfig(level=logging.DEBUG,...

Python运行不显示DOS窗口的解决方法

方法1:pythonw xxx.py 方法2:将.py改成.pyw (这个其实就是使用脚本解析程序pythonw.exe) 跟 python.exe 比较起来,pythonw.exe 有...

在Django同1个页面中的多表单处理详解

在Django同1个页面中的多表单处理详解

快速上手Django实现项目 近期公司在做1个海淘的项目,APP为pylot。由于时间比较赶,加上隔壁那哥们不在,只能自己挑大梁了。结果,当项目做出来之后,被领导狠狠的批了一顿,说怎么用...