Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Name: Lê Quốc Hưng

Student ID: 10423050


Deadline: 23/11/2023

1. Writing a Python program to do the followings:


a. Read the file “numbers.txt” (included in the email’s attachment), each line in the
file containing the numbers separated by commas
b. For each line in the file, print out the followings:
i. The smallest and largest number
ii. The mean of the numbers

Example:
1,8,9.2,-5 -> Min = 1, Max = 9, Mean = 3.55

Please paste the screenshots of your solution to this file and send the file to the email
vuducly151092@gmail.com

with open('numbers.txt', 'r') as file:


for line in file:
numbers = [float(num) for num in line.split(',')]
smallest, largest = min(numbers), max(numbers)
mean = sum(numbers) / len(numbers)
print(f"Smallest: {smallest}, Largest: {largest}, Mean: {mean}")

You might also like