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

Iteration Coding

The document contains code to calculate statistics (sum, average, maximum, minimum) of 20 input values. It also contains code to manage student and teacher records in lists. The code allows a user to input student or teacher details and add them to the appropriate list. It also displays the student or teacher records as needed. The student record includes name, status, age and calculated fees while the teacher record includes name, teaching level and subject.
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)
38 views

Iteration Coding

The document contains code to calculate statistics (sum, average, maximum, minimum) of 20 input values. It also contains code to manage student and teacher records in lists. The code allows a user to input student or teacher details and add them to the appropriate list. It also displays the student or teacher records as needed. The student record includes name, status, age and calculated fees while the teacher record includes name, teaching level and subject.
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

Marienne Denise O.

Martinez

BSIT

Problem # 1

#Allowing user to enter 20 values

sum = 0

max = float()

min = float()

#Ask user to input twenty values

print("Please enter values (20):")

for n in range(20):

val = float(input(f"Val {n+1}: "))

sum += val

if val > max:

max = val

if val < min:

min = val

#Calculate the average

ave = sum / 20

#Print the sum

print("Sum:", sum)

#Print the average

print("Average:", ave)

#Print the maximum

print("Maximum:", max)

#Print the minimum

print("Minimum:", min)
Problem # 2

#Empty list for students and teachers

students = []

teachers = []

#Calculate the fees for student

def calculate_sfees(student):

if student['status'] == 'regular':

return 20000

elif student['status'] == 'new':

return 30000

elif student['status'] == 'transferee':

return 40000

else:

return 0

while True:

#Ask user to input from choices

print("Welcome to University of Batangas! \nPlease see the options below:")

print("1 - Add student")

print("2 - Add teacher")

print("3 - Student list")

print("4 - Teacher list")

choice = int(input("Please enter choice from 1-4: "))

#Adding a student in the list

if choice == 1:
#Ask user to input name, age and status

name = input("Enter student name: ")

status = input("Enter student status (regular, new, or transferee): ")

age = int(input("Enter student age: "))

student = {'name': name, 'status': status, 'age': age}

student['fees'] = calculate_fees(student)

students.append(student)

print("Student added.")

#Adding a teacher in the list

elif choice == 2:

name = input("Enter teacher name: ")

level = input("What level will she/he teach? ")

subject = input("Specialized in which subject? ")

teacher = name, level, subject

teachers.append(teacher)

#Display the teacher successfully added to the list

print("Teacher has been added to the list.")

print("Thank you and come again!")

#Displaying student records

elif choice == 3:

print("\nStudent Records")

for student in students:

#Show the student name, status, age, and school fees

print("\nStudent Name:", name)

print(f"Status: {student['status']}")

print("Age: ", age)

print(f"Fees: P{student['sfees']}")
#Displaying the teacher records

elif choice == 4:

print("\nTeacher Records")

for teacher in teachers:

print("Name: ", name)

print("Level: ", level)

print("Subject: ", subject)

# invalid choice

else:

print("Sorry, invalid choice. Please try again")

You might also like