资料内容:
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()