python獲取從命令行輸入數(shù)字的方法
更新時間:2015年04月29日 09:34:08 作者:重負在身
這篇文章主要介紹了python獲取從命令行輸入數(shù)字的方法,涉及Python操作命令行輸入的相關技巧,需要的朋友可以參考下
本文實例講述了python獲取從命令行輸入數(shù)字的方法。分享給大家供大家參考。具體如下:
#----------------------------------------
# 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 filecmp.dircmp實現(xiàn)遞歸比對兩個目錄的方法
這篇文章主要介紹了python filecmp.dircmp實現(xiàn)遞歸比對兩個目錄的方法,本文通過實例代碼給大家介紹的非常詳細,大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-05-05
python 動態(tài)遷移solr數(shù)據(jù)過程解析
這篇文章主要介紹了python 動態(tài)遷移solr數(shù)據(jù)過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-09-09
Python?pyecharts?Boxplot箱線圖的實現(xiàn)
本文主要介紹了Python?pyecharts?Boxplot箱線圖的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-05-05
對python創(chuàng)建及引用動態(tài)變量名的示例講解
今天小編就為大家分享一篇對python創(chuàng)建及引用動態(tài)變量名的示例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-11-11
OpenCV3.0+Python3.6實現(xiàn)特定顏色的物體追蹤
這篇文章主要為大家詳細介紹了OpenCV3.0+Python3.6實現(xiàn)特定顏色的物體追蹤,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-07-07

