Practical Exam_85 minutes_Python 4th
Practical Exam_85 minutes_Python 4th
3. Code
class employee:
age = 0
salary = 0
name = ''
def set_age(self):
self.age = input('Enter age: ')
def get_age(self):
return self.age
def set_salary(self):
self.salary = input('Enter salary: ')
def get_salary(self):
return self.salary
def set_name(self):
self.name = input('Enter name: ')
def get_name(self):
return self.name
lst=[]
for i in range(5):
print('Enter employees :{}'.format(i+1))
tmp_st = employee()
tmp_st.set_name()
tmp_st.set_age()
tmp_st.set_salary()
lst.append(tmp_st)
print('before sorting:')
for i in range(5):
print('Employees {}'.format(i+1))
print('Name : {}'.format(lst[i].get_name()))
print('Salary : {}'.format(lst[i].get_salary()))
print('Age : {}'.format(lst[i].get_age()))
print('after sorting:')
for i in range(5):
print('Employees {}'.format(i+1))
print('Name : {}'.format(lst[i].get_name()))
print('Salary : {}'.format(lst[i].get_salary()))
print('Age : {}'.format(lst[i].get_age()))
def calculate_series_sum(n):
total = 0
for i in range(1, n + 1):
if i % 2 == 1:
total += i**2
else:
total -= i**2
return total
def main():
print("1. Find the sum of the series S = 1 -
2^2 + 3^2 - ... + n^2 (1 point)")
print("2. Option 2 (not implemented)")
print("3. Option 3 (not implemented)")
selection = input("Your selection (1 -> 3): ")
if selection == "1":
n = int(input("Enter the number of terms:
"))
result = calculate_series_sum(n)
print("OUTPUT")
print(result)
print("FINISH")
if __name__ == "__main__":
main()