Python知识分享网 - 专业的Python学习网站 学Python,上Python222
《1000 Examples Programming In Python》1000个Python编程示例 PDF 下载
发布于:2024-04-20 14:19:28
(假如点击没反应,多刷新两次就OK!)

《1000 Examples Programming In Python》1000个Python编程示例 PDF 下载  图1

 

资料内容:

 

 

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()