class student:
def __init__(self, num, name, academy, major):
self.num = num
self.name = name
self.academy = academy
self.major = major
s1 = student("1", "张三", "软件学院", "软件工程")
print(s1.num+":"+s1.name+" "+s1.academy+" "+s1.major)
class student:
def __init__(self, num, name, academy, major):
self.num = num
self.name = name
self.academy = academy
self.major = major
class group:
def __init__(self):
self.member = []
def add_member(self, *args):
for s in args:
st = student(s.num, s.name, s.academy, s.major)
self.member.append(st)
s1 = student("1", "张三", "软件学院", "软件工程")
s2 = student("2", "李四", "软件学院", "软件工程")
s3 = student("3", "王五", "软件学院", "软件工程")
group_list = group()
group_list.add_member(s1, s2, s3)
for m in group_list.member:
print(m.num+":"+m.name+" "+m.academy+" "+m.major)
class student:
def __init__(self, num, name, academy, major):
self.num = num
self.name = name
self.academy = academy
self.major = major
class group:
def __init__(self):
self.member = []
def add_member(self, *args):
for s in args:
st = student(s.num, s.name, s.academy, s.major)
self.member.append(st)
def alter_name(self, position, name):
self.member[position-1].name = name
s1 = student("1", "张三", "软件学院", "软件工程")
s2 = student("2", "李四", "软件学院", "软件工程")
s3 = student("3", "王五", "软件学院", "软件工程")
group_list = group()
group_list.add_member(s1, s2, s3)
s4 = student("4", "周六", "软件学院", "软件工程")
group_list.add_member(s4)
group_list.alter_name(position=1, name="张三改")
for m in group_list.member:
print(m.num+":"+m.name+" "+m.academy+" "+m.major)
name_list = input("请输入小组成员的姓氏(空格分隔):")
name_set = set(name_list.split(" "))
print("小组成员的姓氏有:")
for name in name_set:
print(name, end=" ")
class grades:
class student:
def __init__(self, name, grade):
self.name = name
self.grade = grade
def __init__(self):
self.member = []
def add_member(self, *args, **kwargs):
for s in args:
st = self.student(s.name, s.grade)
self.member.append(st)
for key in kwargs:
print(key, kwargs[key])
st = self.student(key, kwargs[key])
self.member.append(st)
def count_number(self):
return len(self.member)
def sum_grade(self):
sum = 0
for m in self.member:
sum += m.grade
return sum
def average_grade(self):
return round(self.sum_grade()/self.count_number(), 1)
group_grades = grades()
group_grades_dic = {"张三": 79, "李四": 98, "王五": 67, "周六": 89}
group_grades.add_member(**group_grades_dic)
print("组员总人数:", group_grades.count_number())
print("组员总分:", group_grades.sum_grade())
print("组员平均分:", group_grades.average_grade())
class grades:
class student:
def __init__(self, name, grade):
self.name = name
self.grade = grade
def __init__(self):
self.member = []
def add_member(self, *args, **kwargs):
for s in args:
st = self.student(s.name, s.grade)
self.member.append(st)
for key in kwargs:
st = self.student(key, kwargs[key])
self.member.append(st)
def count_number(self):
return len(self.member)
def sum_grade(self):
sum = 0
for m in self.member:
sum += m.grade
return sum
def average_grade(self):
return round(self.sum_grade()/self.count_number(), 1)
def fail(self):
return {m.name: m.grade for m in self.member if m.grade < 60}
group_grades = grades()
group_grades_dic = {"张三": 56, "李四": 98, "王五": 67, "周六": 89}
group_grades.add_member(**group_grades_dic)
print("低于60分的人:")
failed = group_grades.fail()
for name in failed:
print(name, end=" ")
print(failed[name])
import random
class grades:
class student:
def __init__(self, name, grade):
self.name = name
self.grade = grade
def __init__(self):
self.member = []
def add_member(self, *args, **kwargs):
for s in args:
st = self.student(s.name, s.grade)
self.member.append(st)
for key in kwargs:
st = self.student(key, kwargs[key])
self.member.append(st)
def count_number(self):
return len(self.member)
def sum_grade(self):
sum = 0
for m in self.member:
sum += m.grade
return sum
def average_grade(self):
return round(self.sum_grade()/self.count_number(), 1)
def fail(self):
return {m.name: m.grade for m in self.member if m.grade < 60}
def slice(self, x, y):
m_slice = self.member[x:y]
grades_slice = [m.grade for m in m_slice]
return grades_slice
group_grades = grades()
group_grades_dic = {"张三": 56, "李四": 98, "王五": 67, "周六": 89}
group_grades.add_member(**group_grades_dic)
length = group_grades.count_number()
x = random.randint(1, length-2)
y = random.randint(x+1, length-1)
group_slice = group_grades.slice(x, y)
print("组员成绩[{}:{}]切片的成绩:".format(x, y))
for g in group_slice:
print(g, end=" ")
iterator = (i*7 for i in range(10))
to_list = []
for num in iterator:
to_list.append(num)
print(to_list)
import re
def remove_punctuation(text):
punctuation = '!,.;:?"\'、,;'
text = re.sub(r'[{}]+'.format(punctuation), '', text)
return text.strip()
text = "Please send this message to those people who mean something " \
"to you,to those who have touched your life in one way or " \
"another, to those who make you smile when you really need" \
" it, to those that make you see the brighter side of things " \
"when you are really down,to those who you want to let them " \
"know that you appreciate their friendship.And if you don’t, " \
"don’t worry,nothing bad will happen to you,you will just " \
"miss out on the opportunity to brighten someone’s day with this message."
text_r = remove_punctuation(text)
text_r = text_r.lower()
words = text_r.split(" ")
words_set = set(words)
words_dic = {word: 0 for word in words_set}
for word in words:
words_dic[word] += 1
print(words_dic)
print("一共需要{}粒米".format(sum([2**i for i in range(64)])))
经过这次作业,我深刻地发现对于python的学习,还是有很多的不足,很多地方都没有理解透彻,所以在以后的学习中,应该更仔细地理解语句的用法,加深对其的记忆。