본문 바로가기
728x90
반응형
SMALL

전체 글375

python) Explanation of the Code Using a Dictionary to Represent Students def create_student(name, korean, math, english, science): return { "name": name, "korean": korean, "math": math, "english":english, "science": science } students = [ create_student("윤인성", 87,98,88,95), create_student("연하진",92,98,96,98), create_student("구지연",98,96,90,89), create_student("나선주",88,86,64,87), create_student("윤아린",98,99,78,80), ] print("name", "total", "average", sep="\t") for studen.. 2024. 11. 7.
python) Explanation of the Improved Student Management Code def create_student(name,korean,math,english,science): return{ "name":name, "korean":korean, "math":math, "english":english, "science":science } def student_get_sum(student): return student["korean"]+student["math"]+student["english"]+student["science"] def student_get_average(student): return student_get_sum(student)/ len(student) def student_to_string(student): return "{}\t{}\t{}".format(studen.. 2024. 11. 6.
python) datetime package import datetime now = datetime.datetime.now() print(now.year, now.month, now.day, now.hour, now.minute, now.second); This code snippet is a straightforward example of how to use the `datetime` module in Python to get the current date and time, and then print specific components of it such as the year, month, day, hour, minute, and second. Let's break it down: 1. **`import datetime`**: This line .. 2024. 11. 5.
python) Explanation of the Flatten Functions def flatten(data): output = [] for item in data: if type(item) == list: output += item else: output.append(item) return output def flatten2(data): output=[] for item in data: if type(item) == list: output +=flatten2(item) else: output.append(item) return output example = [[1,2,3],[4,[5,6]],[7,[8,9]]] print("origin : ",example) print("flattened : ",flatten(example)) print("flattened2 : ",flatten2.. 2024. 11. 4.
728x90
반응형
LIST