'''A test'''
1.组合数据类型
info = ['***', 18, 1007, 100]
print('my name is:', info[0])
print('I am :', info[1], 'old')
print('my students_is: ',info[2])
print('my score is:', info[3])
2.加法函数
def add(a, b):
return a + b
print(add(1,2))
#数值自己改
3.减法函数
def sub(a, b):
return a - b
print(sub(1,2))
#数值自己改
4.创建Person类
class Person:
def __init__(self, name, sex, age):
self.__name = name
self.__sex = sex
self.__age = age
def show(self):
print('my name is:', self.__name, '\ti am a: ', self.__sex, '\ti am : ', self.__age, 'years old')
5.创建Student类并继承Person
class Student(Person):
def __init__(self,name,sex,age,stuID):
Person.__init__(self,name, sex, age)
self.__stuID = stuID
def show_stu(self):
Person.show(self)
print('My students_id is: ',self.__stuID)
my=Student('马玉泉','男',23,211322)
my.show_stu()
6.创建文件并写入
with open('C://Users//Public//姓名.txt', mode='w') as f:
f.write('我的姓名是***')
7.不限第三库,代码无误, 图片下载成功即可
import requests
url='https://img1.baidu.com/it/u=2693481522,4085270923&fm=253&fmt=auto&app=120&f=JPEG?w=650&h=434'
#里面的图片网址自个找
response=requests.get(url)
print(response.status_code)
response.encoding = 'utf-8'
response.encoding = 'GBK'
#下面的变量名自己编一个
jpg=open('get.jpg','wb')
jpg.write(response.content)
8.绘制正弦函数图
import matplotlib.pyplot as plt
import numpy as np
import math
x = np.arange(0, 10, 0.1)
y = [math.sin(each) for each in x]
plt.plot(x, y)
plt.show()
'''B test'''
1.创建一个1-50的随机数,并依次输出
import random
m_list = []
for i in range(0,50):
m_list.append(random.randint(0, 50))
a=m_list[i]
print(a,end='/')
2.乘法函数
def mutl(a,b):
return a*b
print(mutl(2,3))
3.除法函数
def divd(a,b):
return a/b
print(divd(4,2))
4.创建Person类
class Person:
def __init__(self, name, sex, age):
self.__name = name
self.__sex = sex
self.__age = age
def show(self):
print('my name is:', self.__name, '\ti am a: ', self.__sex, '\ti am : ', self.__age, 'years old')
5.创建Student类并继承Person
class Student(Person):
def __init__(self,name,sex,age,stuID):
Person.__init__(self,name, sex, age)
self.__stuID = stuID
def show_stu(self):
Person.show(self)
print('My students_id is: ',self.__stuID)
my=Student('马玉泉','男',23,211322)
my.show_stu()
6.输出某路径下的所有文件和文件夹的名称
import os
m_dir='D://aDdownload'
#路径自己找一个
for filename in os.listdir(m_dir):
print(filename)
7.获取网页的状态码和内容
import requests
url='*****'
response=requests.get(url)
print(response.status_code)
response.encoding=response.apparent_encoding
print(response.text)
8.绘制地图,筛选出以'r'开头的国家
from pygal_maps_world import maps
from pygal_maps_world.i18n import COUNTRIES
worldmap_chart=maps.World()
worldmap_chart.title='R Counties'
rcodes=[]
for each in COUNTRIES:
if each.startswith('r'):
rcodes.append(each)
worldmap_chart.add('R counties',rcodes)
worldmap_chart.render_to_file('map.svg')