0% found this document useful (0 votes)
6 views5 pages

Python Code

The document is an individual assignment for a Computer Programming II course at Haramaya University, prepared by a student named Kedefla Nure. It includes several programming tasks such as calculating employee salaries, manipulating strings, calculating BMI, validating dates, and generating a Syracuse sequence. Each task is accompanied by Python code that demonstrates the required functionality.

Uploaded by

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

Python Code

The document is an individual assignment for a Computer Programming II course at Haramaya University, prepared by a student named Kedefla Nure. It includes several programming tasks such as calculating employee salaries, manipulating strings, calculating BMI, validating dates, and generating a Syracuse sequence. Each task is accompanied by Python code that demonstrates the required functionality.

Uploaded by

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

HARAMAYA UNIVERSITY

COLLEGE OF COMPUTING AND INFORMATICS

DEPARTMENT OF SOFTWARE ENGINEERING

COMPUTER PROGRAMMING II

INDIVIDUAL ASSIGNMENT

PREPARED BY :-
Name:- ID
1.Kedefla Nure ……………………………….. 1724/16
SUBMITTED TO:- ABDATA J. Submission
Date:-06/2/2025

''' 1. Calculate the salary of each employee and append them to your original
lists inside the dictionary.'''

# Employee data dictionary

employees = {

"seid": [10000, 0.05, 5000],

"chala": [2000, 0.05, 5000],

"abenezer": [4000, 0.05, 5000],

"abel": [20000, 0.05, 5000],

"kebede": [8000, 0.05, 5000],

"mohammed": [5000, 0.05, 5000]

# Calculate total salary and update dictionary

for name, data in employees.items():

sell, percent, fixed_salary = data

total_salary = fixed_salary + (sell * percent)

data.append(total_salary) # Append total salary

# Print dictionary in required format

print("\nName\t\tTotal Salary")

for name, data in employees.items():

print(f"{name.capitalize()}\t\t{data[3]}")

# Top 3 highest-paid employees

top_3 = sorted(employees.items(), key=lambda x: x[1][3], reverse=True)[:3]


print("\nTop 3 employees which is highly paid:")

for name, data in top_3:

print(f"{name.capitalize()}: {data[3]}")

# Employees with salary greater than 5500

print("\nEmployees earning more than 5500:")

for name, data in employees.items():

if data[3] > 5500:

print(f"{name.capitalize()}: {data[3]}")

''' 2. Write a Python program to get a string made of the first 2 and the last 2
chars from a given string. If the string length is less than 2, return instead
the empty string.'''

s = input("Enter a string: ")

if len(s) >= 2:

result = s[:2] + s[-2:]

else:

result = ""

print(result)

''' 3. Write a program that calculates a person’s BMI and prints a message
telling whether they are above, within, or below the healthy range.'''

weight = float(input("Enter weight in kilograms: "))

height = float(input("Enter height in meters: "))

bmi = weight / (height ** 2)


if 19 <= bmi <= 25:

print(f"BMI: {bmi} (You’re in Healthy range)")

elif bmi < 19:

print(f"BMI: {bmi} (you’re Below healthy range)")

else:

print(f"BMI: {bmi} (You’re Above healthy range)")

''' 4. Write a program that calculates a person’s BMI and prints a message
telling whether they are above, within, or below the healthy range'''

date_input = input("Enter date (MM/DD/YYYY): ")

month, day, year = date_input.split('/')

month = int(month)

day = int(day)

year = int(year)

# Check if it's a leap year

is_leap = (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)

# Number of days in each month

if month in [1, 3, 5, 7, 8, 10, 12]:

max_days = 31

elif month in [4, 6, 9, 11]:

max_days = 30

elif month == 2:

max_days = 29 if is_leap else 28 # February has 29 days in a leap year

else:

max_days = 0 # Invalid month


# Check if the day is valid

if 1 <= day <= max_days:

print("Valid date")

else:

print("Invalid date")

''' 5. Write a program that gets a starting value from the user and then prints
the Syracuse sequence for that starting value.'''

n = int(input("Enter a number: "))

sequence = [n]

while n != 1:

if n % 2 == 0:

n = n // 2

else:

n = (3 * n) + 1

sequence.append(n)

print(sequence)

You might also like