Mivan 2025 Python歌单生成器
1. Assignment Task
Use Python advanced programming to develop a computer program
| Achievement | Achievement with Merit | Excellence |
|---|---|---|
| Use advanced programming techniques to develop a computer program. | Use advanced programming techniques to develop an informed computer program. | Use advanced programming techniques to develop a refined computer program. |
2. Requirements
In this Activity, you will be assessed on how effectively you refine your program to ensure that the program:
is a well-structured, logical response to the specified task
has been comprehensively tested and debugged
is flexible and robust.
You should consider these examples of ways of making a program flexible and robust:
- using actions, conditions, control structures and methods, functions, or procedures effectively
- checking input data for validity
- correctly handling expected, boundary and invalid cases
- using constants, variables and derived values in place of literals.
When developing your program, you must ensure your program:
- uses variables storing at least two types of data (e.g. numeric, text, Boolean) • uses sequence, selection and iteration control structures
- takes input from a user, sensor(s), or other external source(s)
- produces output
- follows common conventions of the chosen programming language
- is documented with appropriate variable/module names and comments that describe the code function and behaviour.
Your program must use two or more advanced programming techniques.
Examples of advanced programming techniques include writing code that:
- modifies data stored in collections (e.g. lists, arrays, dictionaries)
- defines and manipulates multidimensional data in collections
- creates methods, functions, or procedures that use parameters and/or return values • responds to events generated by a graphical user interface (GUI)
- requires non-basic string manipulation
- uses functionality of additional non-core libraries.
3. Problem Statement:
Spotify and Apple Music use aggressive algorithms to push more of the same content, once a user expresses an interest in a certain style of music (Hristova, Hong, & Slack, 2020). You want to use your newfound Python programming skills to build a simplified version of this algorithm that builds a playlist based on the number of plays.
Add three exclamation points in the header as comments.
Your program will allow the user to enter the song, artist, and number of plays. Your program will ask the user to enter a number and generate a playlist of all songs that have that number of plays or more. For testing purposes, you should populate your program with sample data of at least 5 songs.
Your program will let you:
- Print all songs (show song and artist),
- Enter a song, artist, and number of plays,
- Edit the number of plays,
- Delete a song from your records,
- Generate a playlist from a minimum number of plays,
- Exit
The interaction will be through a menu which could look something like:
Menu:
- Print all songs
- Add a song
- Change number of plays for a song
- Delete a song
- Generate playlist by minimum number of plays
- Exit
Enter your choice:
4. Student instructions
Your task for this is to:
- Populate your collections with sample data.
- Write the code for a program that performs the specified task.
- Use two (or more) advanced programming techniques in Python.
- You must show version control [either using the drops in Google Classroom or GitHub].
- If you use GitHub, you must make your repository private and add your teacher as a collaborator.
- Follow conventions for Python.
- Set out the program code clearly and document the program with succinct comments.
- Test and debug the program. You should ensure that you document all the test cases, the results of your testing and any changes you make as a result of your testing.
5. Development
You should break the program up into components. Think about what information each component will need to do its job, and what information it will pass on to the rest of the program. Code, test and debug each component separately. As you complete each section you should save your code with a new version number.
Note: To test a program in a comprehensive way, you should think about how you will test the program for various cases such as expected, boundary and unexpected input. It is often useful to note down what you want to test and what you expect to happen, as well as what actually happened. Testing can be demonstrated by making a brief screencast showing the program being comprehensively tested. If desired, you can take screenshots of your screencast and annotate them.
Ensure that you comment your code appropriately as you develop it and use variable/module names and comments that describe code function and behaviour.
Ensure that you have followed conventions for the programming language of your choice and that your program is a well-structured, logical response to the task.
Note: You can use the online PEP8 style checker to show that your program has met the PEP8 conventions. This does not mean you can ignore using clear variable and constant names.
You should ensure that your code is robust and that it handles expected, boundary and invalid cases.
Wherever possible you should try to ensure that your code has a flexible structure to allow for continued development.
6. Submission
When you have finished your program and its testing, check that you have met the requirements of the marking schedule.
- Your source code;
- Your testing document;
- Your README file explaining how to run your program;
- Your lite documentation detailing your process.
7. Using lists code
"""
Student_dictionary.py
A dictionary of students that holds their names, ethnicity and age
Allows the user to add and delete a student and change their age
Can list the ethnicity of all the students and all the students of a certain age
"""
def add_student(name, ethnicity, age):
"""
Add a student to the records.
name - string: the name of the student.
ethnicity - string: that is the ethnicity of the student.
age - int: the age of the student.
"""
names.append(name)
ethnicities.append(ethnicity)
ages.append(age)
return names, ethnicities, ages
def change_age(name, new_age, ages):
"""
Change the age of a student.
name - string: the name of the studnet whoes age to change
new_age - int: the new age of the student
ages - list: the ages of all students
"""
#what if students do not exsit?
student_index = names.index(name) # look for index of student
# change the student's age to the new_age
ages[student_index] = new_age
print("Age for {} updated to {}.".format(name, new_age))
return ages
def delete_age(name, names, ethnicities, ages):
"""
Delete a student from the records.
name - string: the name of the student to delete
names - list: the list of student names
ethnicities - lists: the list of student ethnicities.
ages - list: the list of student ages.
"""
studnet_index = names.index(name) # look for index of student
#delete the student based on the idex. ? what if students are not there?
del names[student_index]
del ethnicities[student_index]
del ages[student_index]
print("{} deleted from records.".format(name))
def list_all_ethnicities():
"""
List all unique ethnicities of students
"""
print("Ethnicities of all students")
# Holds all ethnicities
seen_ethnicities = []
#Search through the ethnicities
for ethnicity in ethnicities:
#if it has not been seen add to list
if ethnicity not in seen_ethnicities:
print(ethnicity)
seen_ethnicities.append(ethnicity)
def find_students_by_age(target_age):
"""
Find students of a specific age.
target_age - int: the age to search for.
"""
# Holds list of students at target age
students = []
# Loop over list of students
for i in range(len(names)):
# Check their age matches the target age and add to list
if ages[i] == target_age:
students.append(names[i])
# Show all students who are at target age
for student in students:
print(student)
def main():
"""Main function to run the program.
"""
while True:
print("\nMenu:")
print("1. Add a student")
print("2. Change age for a student")
print("3. Delete a student")
print("4. List all ethnicities")
print("5. Find students by age")
print("6. Exit")
choice = input("Enter your choice: ")
if choice == "1":
name = input("Enter student's name: ")
ethnicity = input("Enter student's ethnicity: ")
age = int(input("Enter student's age: "))
names, ethnicities, ages = add_student(name, ethnicity, age) #update students
elif choice == "2":
name = input("Enter student's name: ")
new_age = int(input("Enter student's new age: "))
ages = change_age(name, new_age, ages) # update the ages list
elif choice == "3":
name = input("Enter student' name: ")
names, ethnicities, ages = delete_student(name) # update students
elif choice == "4":
list_all_ethnicities()
elif choice == "5":
target_age = int(input("Enter age for search for: "))
find_students_by_age(target_age)
elif choice == "6":
print("Exiting program.")
break
else:
print("Invalid choice. Please enter a number from 1 to 6.")
if __name__ =="__main__":
# Parallel list of student attributes
names = []
ethnicities = []
ages = [] # The three parallel lists are not well-structured, thinking of addressing it.
main()8. Using dictionaries code
""" Using dictionaries to deal with students question"""
def add_student(students):
"""add a new student to the system"""
name = input("Enter student name: ").strip().lower()
if name in students:
print("Student already exists!")
ethnicity = input("Enter student ethnicity: ").strip().lower()
age = get_valid_age()
students[name] = {
'ethnicity': ethnicity,
'age': age
}
print("Student {} added successfully.".format(name))
def update_student_age(students):
"""Update the age of an existing student."""
name = input("Enter student name to update age: ").strip()
if name not in students:
print("Student not found!")
else:
new_age = get_valid_age()
students[name]['age'] = new_age
print("Age updated for {} to {}".format(name, new_age))
def delete_student(students):
"""Remove a student from the system"""
name = input("Enter student name to delete: ").strip()
if name not in students:
print("Students not found!")
else:
del students[name]
print("Student {} deleted successfully!".format(name))
def list_all_ethnicities(students):
"""Display all unique ethnicities in the system"""
for student in students.values():
ethnicities = student['ethnicity']
print(ethnicities)
def find_by_ethnicity(students):
"""Find and display students of a specific ethnicity"""
ethnicity = input("enter ethnicity to search for: ").strip()
names = []
for name, eth in students.items():
if eth['ethnicity'] == ethnicity.lower():
names.append((name, eth['age']))
print(names)
def get_valid_age():
"""Helper function to get and validate age input"""
MAX_AGE = 120
MIN_AGE = 0
while True:
try:
age = int(input("Enter age: "))
if MAX_AGE > age > MIN_AGE:
return age
else:
print("Age must be in the range of 0-120")
except ValueError:
print("Age must be a number! Try again.")
def print_all_students(students):
""" Print all keys in the dictionary"""
print(students)
def find_by_age(students):
"""Find and display students of a specific age"""
age = input("enter ethnicity to search for: ").strip()
names = []
for name, age_student in students.items():
if age_student['age'] == age.lower():
names.append((name, age_student['ethnicity']))
print(names)
def main():
students = {} # Main dictionary to store student data
while True:
print("\nStudent Management System")
print("1. Add a student")
print("2. Update student age")
print("3. Delete a student")
print("4. List all ethnicities")
print("5. Find students by ethnicity")
print("6. Find students by age")
print("7. Print all students")
print("8. Exit")
choice = input("Enter your choice (1-7): ")
if choice == "1":
add_student(students)
elif choice == "2":
update_student_age(students)
elif choice == "3":
delete_student(students)
elif choice == "4":
list_all_ethnicities(students)
elif choice == "5":
find_by_ethnicity(students)
elif choice == "6":
find_by_age(students)
elif choice == "7":
print_all_students(students)
elif choice == "8":
print("Exiting the system. Goodbye!")
break
else:
print("Invalid choice. Please enter a number between 1-7.")
if __name__ == "__main__":
main()公众号:AI悦创【二维码】

AI悦创·编程一对一
AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」,招收学员面向国内外,国外占 80%。全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然,还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线,随时响应!微信:Jiabcdefh
C++ 信息奥赛题解,长期更新!长期招收一对一中小学信息奥赛集训,莆田、厦门地区有机会线下上门,其他地区线上。微信:Jiabcdefh
方法一:QQ
方法二:微信:Jiabcdefh

更新日志
b2b61-于f6b0c-于098e8-于1bf2d-于68665-于8b044-于58ad0-于4d098-于1c35a-于cbb3a-于76989-于86c50-于027da-于