Python知識(shí)分享網(wǎng) - 專業(yè)的Python學(xué)習(xí)網(wǎng)站 學(xué)Python,上Python222
《1000 Examples Programming In Python》1000個(gè)Python編程示例 PDF 下載
匿名網(wǎng)友發(fā)布于:2024-04-20 14:19:28
(侵權(quán)舉報(bào))
(假如點(diǎn)擊沒反應(yīng),多刷新兩次就OK!)

《1000 Examples Programming In Python》1000個(gè)Python編程示例 PDF 下載  圖1

 

資料內(nèi)容:

 

 

Exercise: Standard Input
In the previous exercises we expected the
userinput to come in on the “Standard Input” aka.
STDIN.
If you would like to practice this more, come up
with other ideas, try to solve them and tell me
about the task. (in person or via e-mail.)
(e.g. you could start building an interactive role
playing game.)
 
Solution: Area of rectangular
 
1 def main():
2 #length = 10
3 #width = 3
4
5 length = int(input('Length: '))
6 width = int(input('Width: '))
7
8 if length <= 0:
9 print("length is not positive")
10 return
11
12 if width <= 0:
13 print("width is not positive")
14 return
15
16 area = length * width
17 print("The area is ", area)
18
19 main()