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使用sorted排序的方法小结

Python使用sorted排序的方法小结

本文实例讲述了Python使用sorted排序的方法。分享给大家供大家参考,具体如下: # 例1. 按照元素出现的次数来排序 seq = [2,4,3,1,2,2,3] # 按次数排...

python 计算数组中每个数字出现多少次--“Bucket”桶的思想

python 计算数组中每个数字出现多少次--“Bucket”桶的思想

题目: 解法一:比较元素是否相等 思路说明: 这种应该是普通人最先想到的解法,先获取到数组之后进行有小到大排序,然后初始化一个min=0(代表新数字的开始角标),然后遍历新数组的每一个...

python 实现让字典的value 成为列表

如果想让字典的VALUE成为字典,只有最开始让其成为列表,如下面程序中的b >>> b={} >>> b={1:['sdad']} >>...

python实现大战外星人小游戏实例代码

主程序 import pygame from pygame.sprite import Group from settings import Settings from game_...

两个命令把 Vim 打造成 Python IDE的方法

两个命令把 Vim 打造成 Python IDE的方法

运行下面两个命令,即可把 Vim(含插件)配置成 Python IDE。目前支持 MAC 和 Ubuntu。 curl -O https://raw.githubuserconten...