某位港中文同学的python作业,简直是非常简单
#@@####################################@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# Just read the declaration and fill in your personal information
# as below. DO NOT TOUCH the statement content
#@@####################################@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# I declare that the lab work here submitted is original except
# for source material explicitly acknowledged, and that the
# same or closely related material has not been previously
# submitted for another course.
# I also acknowledge that I am aware of University policy and
# regulations on honesty in academic work, and of the
# disciplinary guidelines and procedures applicable to breaches
# of such policy and regulations, as contained in the website.
# University Guideline on
# Academic Honesty: https://www.cuhk.edu.hk/policy/academichonesty/
#
# Name :
# Student ID :
# Class and Section :
# Date :
#@@####################################@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@plaintext# Task 1: Dealing with Tuples
# Create a tuple and store the temperature readings
# TODO: replace '...' and create a "tuple" to store temperature data
temperatures = (23.5, 24.8, 22.1, 26.3, 25.7)
districts = ("Shatin", "Mong kok", "Central", "Tung Chung", "Sunny Bay")
# print all temperature values
print("Temperature Readings:")
for i in range(0, len(temperatures), 1):
# TODO: replace '...' and complete for loop
print(districts[i])
print(temperatures[i])
# TODO: replace '...' and print the temperature values
average_temperature = sum(temperatures) / len(temperatures)
# TODO: replace '...' and calculate the average temperature using len() function
# Calculate minimum temperature value in the tuple
minimum_temperature = min(temperatures)
# TODO: replace '...' and calculate total minimum temperature using min() function and tuple indexing
# Calculate maximum temperature value in the tuple
maximum_temperature = max(temperatures)
# TODO: replace '...' and calculate total maximum temperature using max() function and tuple indexing
# Print the average temperature value, minimum temperature value and maximum temperature value
print("Average Temperature: ",average_temperature)
print("Minimum Temperature: ",minimum_temperature)
print("Maximum Temperature: ",maximum_temperature)
# Task 2: Dealing with Lists
# Initialize a list and store the 5 subject names
subject = ["Math", "Chemistry", "Physics", "Arts", "Language"]
# TODO: replace '...' and create a list of 5 subject name. Check the slide 14 in lab manual
# Initialize an empty list to store the subject marks
marks = []
# TODO: replace '...' and create an empty list for subject marks
# Get the marks for each subject from the user
for item in subject:
message= "Enter the marks for the subject " + item + " : "
subject_mark = int(input(message))
marks.append(subject_mark)
# TODO: replace '...' and write an append function to add subject marks in the marks list
# Calculate the total marks
total_marks = sum(marks)
# TODO: replace '...' and use sum() function to calculate the total marks
# Print the total marks
print("Your total mark is : ", total_marks)
# Calculate the average marks
average_marks = total_marks / len(marks)
# TODO: replace '...' and use total marks and len() function to calculate the average marks
# Print the average marks
print("Your average mark is : ", average_marks)
# Task 3: Dealing with Python Functions
# Create a grade() function
def grade(average_marks):
# TODO: replace '...' and use if-elif-else statement and complete the code to calculate
# the student grade
if average_marks >= 91 and average_marks = 81 and average_marks = 71 and average_marks = 61 and average_marks = 51 and average_marks = 41 and average_marks < 51:
grade = "E"
else:
grade = "Fail"
return grade
# Call the grade() function
student_grade = grade(average_marks)
# TODO: replace '...' and call the grade function
# Print the student grade for a student
print("Your student grade is : ", student_grade)
# Bonus Task 4: Dealing with Python Functions
def gpa(grade):
if grade == "A+":
gpa = 4.0
elif grade == "A":
gpa = 3.5
elif grade == "B":
gpa = 3.0
elif grade == "C":
gpa = 2.5
elif grade == "D":
gpa = 2.0
elif grade == "E":
gpa = 1.0
else:
gpa = 0.0
return gpa
# TODO: Create a gpa() function to calculate the student GPA
student_gpa = gpa(student_grade)
# TODO: Call the gpa() function
print("Your student gpa is : ", student_gpa)
# TODO: Print the student gpa for a studentplaintext