python獲取從命令行輸入數(shù)字的方法
本文實(shí)例講述了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...' )
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
Python采集貓眼兩萬(wàn)條數(shù)據(jù) 對(duì)《無(wú)名之輩》影評(píng)進(jìn)行分析
這篇文章主要給大家介紹了關(guān)于利用Python榮國(guó)采集兩萬(wàn)條貓眼數(shù)據(jù),對(duì)《無(wú)名之輩》影評(píng)進(jìn)行分析的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-12-12Python爬蟲(chóng)實(shí)現(xiàn)爬取百度百科詞條功能實(shí)例
這篇文章主要介紹了Python爬蟲(chóng)實(shí)現(xiàn)爬取百度百科詞條功能,結(jié)合完整實(shí)例形式分析了Python爬蟲(chóng)的基本原理及爬取百度百科詞條的步驟、網(wǎng)頁(yè)下載、解析、數(shù)據(jù)輸出等相關(guān)操作技巧,需要的朋友可以參考下2019-04-04Python數(shù)組拼接np.concatenate實(shí)現(xiàn)過(guò)程
這篇文章主要介紹了Python數(shù)組拼接np.concatenate實(shí)現(xiàn)過(guò)程,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04Python中SOAP項(xiàng)目的介紹及其在web開(kāi)發(fā)中的應(yīng)用
這篇文章主要介紹了Python中的SOAP項(xiàng)目及其在web開(kāi)發(fā)中的應(yīng)用,本文來(lái)自于IBM官方網(wǎng)站技術(shù)文檔,需要的朋友可以參考下2015-04-04PyTorch中Tensor和tensor的區(qū)別及說(shuō)明
這篇文章主要介紹了PyTorch中Tensor和tensor的區(qū)別及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07python從內(nèi)存地址上加載python對(duì)象過(guò)程詳解
這篇文章主要介紹了python從內(nèi)存地址上加載pythn對(duì)象過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-01-01python+selenium實(shí)現(xiàn)163郵箱自動(dòng)登陸的方法
本篇文章主要介紹了python+selenium實(shí)現(xiàn)163郵箱自動(dòng)登陸的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-12-12Python將多個(gè)list合并為1個(gè)list的方法
今天小編就為大家分享一篇Python將多個(gè)list合并為1個(gè)list的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-06-06Pandas?時(shí)間序列分析中的resample函數(shù)
這篇文章主要介紹了Pandas?時(shí)間序列分析中的resample函數(shù),Pandas?中的resample函數(shù)用于各種頻率的轉(zhuǎn)換工作,下面我們就來(lái)看看其的參數(shù)、相關(guān)資料等,需要的小伙伴可以參考一下,希望給你帶來(lái)幫助2022-02-02