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导出DBF文件到Excel的方法

本文实例讲述了Python导出DBF文件到Excel的方法。分享给大家供大家参考。具体如下: from dbfpy import dbf from time import sleep...

Python实现读取字符串按列分配后按行输出示例

本文实例讲述了Python实现读取字符串按列分配后按行输出。分享给大家供大家参考,具体如下: 问题: 输入一个字符串和一个数字,数字代表分为几行,需要按照给定的列存储方法存储下来之后按行...

Django 中自定义 Admin 样式与功能的实现方法

Django 中自定义 Admin 样式与功能的实现方法

自定义 Admin 样式与功能 1 页面修改中文 1.1 语言设置为中文 settings.py LANGUAGE_CODE = 'zh-hans' 修改结果 1.2 应用管理设置为...

Python日志模块logging基本用法分析

本文实例讲述了Python日志模块logging基本用法。分享给大家供大家参考,具体如下: 1. 基础用法 python提供了一个标准的日志接口,就是logging模块。日志级别有DEB...

python简单线程和协程学习心得(分享)

python中对线程的支持的确不够,不过据说python有足够完备的异步网络框架模块,希望日后能学习到,这里就简单的对python中的线程做个总结 threading库可用来在单独的线程...