1-python作业整活(简洁&小题大做)
例1-1
编写程序,分两行分别打印“Hello World!”和“欢迎使用Python!”。程序保存为example1_1.py。
正常作业
1
2print('Hello world!')
print('欢迎使用Python!')整活
1
print('Hello world!\n欢迎使用Python!')
例1-3
运用三种模块的导入方法求解30度的正弦函数值
正常作业
1
2
3
4
5
6
7
8
9
10
11
12
13
14# 1
import math
x = math.sin(math.radians(30))
print(x)
# 2
from math import sin,radians
x = sin(radians(30))
print(x)
# 3
from math import *
x = sin(radians(30))
print(x)整活
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16# 4
import importlib
module = 'math'
mod = importlib.import_module(module)
print(mod.sin(mod.radians(30)))
# 5
import importlib
module = 'math'
mod = importlib.import_module(module)
objects = dir(mod)
for o in objects:
globals()[o] = getattr(mod,o)
def sin_degree(degree):
return sin(radians(degree))
print(sin_degree(30))
课后作业
编写程序,通过sys模块输出电脑中安装的python版本号。 (保存为exercise1.py)
正常作业
1
2import sys
print(sys.version)整活
1
2
3
4
5
6
7
8
9
10import importlib
module = 'sys'
mod = importlib.import_module(module)
objects = dir(mod)
for o in objects:
globals()[o] = getattr(mod,o)
def version_get():
return version
v = version_get()
print(v)
提交作业
正常作业
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21# 1-1
import sys
print('Hello world!')
print('欢迎使用Python!')
# 1-3
# 1-3-1
import math
x = math.sin(math.radians(30))
print(x)
# 1-3-2
from math import sin,radians
x = sin(radians(30))
print(x)
# 1-3-3
from math import *
x = sin(radians(30))
print(x)
# 课后作业
print(sys.version)我的:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#-- codeing=utf-8 --
#@Time:2024-3-2
#@Author:zzy
#@File:exercise1.py
#@Software:vscode
import sys,math
from math import sin,radians
from math import *
# 1-1
print('Hello world!\n欢迎使用Python!')
# 1-3
print(math.sin(math.radians(30)))
print(sin(radians(30)))
# 1
print(dir(sys))
print(sys.version) # 3.11.8 (tags/v3.11.8:db85d51, Feb 6 2024, 22:03:32) [MSC v.1937 64 bit (AMD64)]