0% found this document useful (0 votes)
21 views

Python Assignment: Basic

An getting started exercise in python with variables, list, functions

Uploaded by

11247275
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Python Assignment: Basic

An getting started exercise in python with variables, list, functions

Uploaded by

11247275
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment 1 - Programming

6198161ng-assignment-1-programming

November 2, 2024

Name: Nguyễn Đỗ Ánh Dương


ID: 11247275
Class: K66-FDA-EP16B

1 Problem 1: Basic statistics calclator


[6]: #setup
num_time = int(input('How many numbers will you enter? '))
num_list = []

#get data
for i in range(1, num_time + 1):
number = float(input(f'Enter number {i}: '))
num_list.append(number)

#statistics
average = sum(num_list) / num_time
print('Minimum:', min(num_list))
print('Maximum:', max(num_list))
print('Average:', '%.2f' %(average))

How many numbers will you enter? 4


Enter number 1: 2
Enter number 2: 56
Enter number 3: 7
Enter number 4: 734
Minimum: 2.0
Maximum: 734.0
Average: 199.75

2 Problem 2: Sentiment analisys on simple user feedback


[2]: #setup list
positive = ['good', 'great', 'exellent', 'amazing', 'awesome', 'cool',
'fabulous', 'fantastic', 'best']
negative = ['bad', 'awful', 'dreadful', 'poor', 'terrible', 'unacceptable',

1
'unsatisfactory', 'disappointing', 'worst','horrible']

#input
num_time = int(input('How many feedback would you like to enter? '))

#get feedbacks
pos_count = 0
neg_count = 0
neu_count = 0

for i in range(1, num_time + 1):


feedback = input(f'Enter feedback {i}: ')
fb_split = feedback.lower().split()
if any(keyword in fb_split for keyword in positive):
pos_count += 1
print(f'Rep {i}: Top performer')
elif any(keyword in fb_split for keyword in negative):
neg_count += 1
print(f'Rep {i}: Average performer')
else:
neu_count += 1
print(f'Rep {i}: Neutral')

#count output
print('Statistic:')
print(f'Positive: {pos_count}')
print(f'Negative: {neg_count}')
print(f'Neutral: {neu_count}')

How many feedback would you like to enter? 3


Enter feedback 1: it was a fantastic product
Rep 1: Top performer
Enter feedback 2: the worst i've ever seen
Rep 2: Average performer
Enter feedback 3: fine enough
Rep 3: Neutral
Statistic:
Positive: 1
Negative: 1
Neutral: 1

3 Problem 3: Sales performance report


[10]: #sale rep classify
def class_rep(x):
if x > 10000:

2
return 'Top Performer'
elif 5000<x<=10000:
return 'Average Performer'
else:
return 'Needs Improvements'

#ask how many sale reps


while True:
try:
a = int(input('How many sale reps data would you like to enter? '))
if a <= 0:
raise ValueError
break
except ValueError:
print('Invalid input! Please enter a numeric value.')

#output
for i in range(1, a + 1):
while True:
try:
sale = float(input(f'Enter sales data for rep {i}: '))
print(f'Rep {i}: {class_rep(sale)}')
break
except ValueError:
print('Invalid input! Please enter a numeric value.')

How many sale reps data would you like to enter? 3


Enter sales data for rep 1: ji
Invalid input! Please enter a numeric value.
Enter sales data for rep 1: 12000
Rep 1: Top Performer
Enter sales data for rep 2: 6000
Rep 2: Average Performer
Enter sales data for rep 3: abc
Invalid input! Please enter a numeric value.
Enter sales data for rep 3: 800
Rep 3: Needs Improvements

You might also like