Description (input)
Select from exercise 7-1 to 7-10
Code (input)
7-3
1 | # 7-3 10的整数倍 :让用户输入一个数字,并指出这个数字是否是10的整数倍。 |
result:1
2
3
4
5
6
7
8
9Enter a number: 120
Yes
Enter a number: 3
No
Enter a number: f
Traceback (most recent call last):
File "D:/pyproject/homework1/7.py", line 3, in <module>
num = int(input("Enter a number: "))
ValueError: invalid literal for int() with base 10: 'f'
7-7
1 | # 7-7 无限循环 :编写一个没完没了的循环,并运行它(要结束该循环,可按Ctrl +C,也可关闭显示输出的窗口)。 |
result:1
2
3
41
2
3
...
7-10
1 | # 7-10 梦想的度假胜地 :编写一个程序,调查用户梦想的度假胜地。使用类似于“If you could visit one place in the world, |
result:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22If you could visit one place in the world, where would you go?HongKong
If you could visit one place in the world, where would you go?America
If you could visit one place in the world, where would you go?HongKong
If you could visit one place in the world, where would you go?Tokyo
If you could visit one place in the world, where would you go?Kyoto
If you could visit one place in the world, where would you go?Tokyo
If you could visit one place in the world, where would you go?Shanghai
If you could visit one place in the world, where would you go?HongKong
If you could visit one place in the world, where would you go?Beside you
If you could visit one place in the world, where would you go?Kyoto
Beside you:
1
Shanghai:
1
Tokyo:
2
Kyoto:
2
HongKong:
3
America:
1
Description (function)
Select from exercise 8-1 to 8-16
Code (function)
8-2
1 | # 8-2 喜欢的图书 :编写一个名为favorite_book() 的函数,其中包含一个名为title 的形参。这个函数打印一条消息, |
result:1
2Which book do you like best?harry potter
One of my favorite books is Harry Potter
8-4
1 | # 8-3 T恤 :编写一个名为make_shirt() 的函数,它接受一个尺码以及要印到T恤上的字样。这个函数应打印一个句子, |
result:1
2
3
4Size: XXL
Print with: I love Python!
Size: L
Print with: Hello world
8-6
1 | # 8-6 城市名 :编写一个名为city_country() 的函数,它接受城市的名称及其所属的国家。这个函数应返回一个格式类似于下面这样的字符串: |
result:1
2
3Guangzhou, China
Tokyo, Japan
Los Angeles, America
8-14
1 | # 8-14 汽车 :编写一个函数,将一辆汽车的信息存储在一个字典中。这个函数总是接受制造商和型号,还接受任意数量的关键字实参。这样调用这个函数:提供必不可 |
result:1
2
3{'brand': 'BMW', 'type': 'gas', 'color': 'black', 'price': '100 milions'}
{'brand': 'Benz', 'type': 'gas'}
{'brand': 'Tesla', 'type': 'eletric', 'appearance': 'cool'}