Write a program that accepts the name of a group of 5 students and their age one by one. The program will then calculate the average of their ages and will print the result. The program will also print the name and age of the oldest person in the list.​

Answers

Answer 1

Here's a Python program that accepts the name and age of five students, calculates the average of their ages, and prints the name and age of the oldest student:

# initialize variables

names = []

ages = []

max_age = 0

max_name = ""

# loop to get names and ages

for i in range(5):

   name = input("Enter student name: ")

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

   names.append(name)

   ages.append(age)

   if age > max_age:

       max_age = age

       max_name = name

# calculate average age

avg_age = sum(ages) / len(ages)

# print results

print("Average age: ", avg_age)

print("Oldest student: ", max_name, max_age)

This program uses a list to store the names and ages of the students. It also keeps track of the maximum age and the corresponding name as it iterates through the input loop. Finally, it calculates the average age and prints out the results.

Answer 2

Answer:

Hey there! I remember based off the last one we needed a beginner friendly version rather than a advanced version! So with that in mind...

names = [None] * 5

ages = [0] * 5

# Collect the names and ages of the 5 students

for i in range(5):

   name = input("Please enter the name of student " + str(i + 1) + ": ")

   age = int(input("Please enter the age of student " + str(i + 1) + ": "))

   names[i] = name

   ages[i] = age

# Calculate the average age

average_age = sum(ages) / len(ages)

# Find the oldest student

oldest_age = max(ages)

oldest_index = ages.index(oldest_age)

oldest_name = names[oldest_index]

# Print the results

print("The average age is:", average_age)

print("The oldest student is " + oldest_name + " with an age of " + str(oldest_age))

Explanation:

We create two lists, names and ages, with 5 elements each. The names list is initialized with None values, and the ages list is initialized with 0 values.

Then, we use a for loop to iterate 5 times, as we want to collect information about 5 students. In each iteration, we ask the user to input the name and age of a student.

We use the input() function to get the name of the student and directly assign it to the corresponding index in the names list using names[i] = name.

We use the int() function to convert the user input into an integer (since age is a whole number) and directly assign it to the corresponding index in the ages list using ages[i] = age.

After collecting all the information, we calculate the average age by summing up all the ages in the ages list using the sum() function and dividing it by the number of students (in this case, 5).

To find the oldest student, we first determine the highest age using the max() function, which returns the maximum value in the ages list. Then, we use the index() method to find the index of the oldest age in the ages list. With this index, we can find the corresponding name of the oldest student in the names list.

Finally, we print the average age and the name and age of the oldest student using the print() function.

NOTE: The main difference in this version of the code is that we initialize the lists with a fixed size and assign values directly to each index instead of using the append() method to add elements to the lists.


Related Questions

Arithmetic Instructions: Activity : Display 3 Digits (Assembly Code)
Hardcode a 3 digit value into a variable. Display the number

Answers

The value 123 is hardcoded into the "number" variable that is defined in this code. The programme then prepares the output by changing the value of "number" and initialising the registers with the proper values.

How many arithmetic instructions are there in three?

Binary, decimal, logical, shift/rotate, and bit/byte manipulation instructions are additional categories for the arithmetic instructions.

section .data

 number db 123 ; hardcode the 3-digit value

section .text

 global _start

_start:

 ; set up the output

 mov eax, 4 ; use the write system call

 mov ebx, 1 ; write to standard output

 mov ecx, number ; move the number variable into ecx

 mov edx, 3 ; print 3 characters

 ; display the number

 int 0x80 ; execute the system call

 ; exit the program

 mov eax, 1 ; use the exit system call

 xor ebx, ebx ; return 0 to indicate success

 int 0x80 ; execute the system call

To know more about programme visit:-

https://brainly.com/question/30307771

#SPJ1

1. Which of the following supports a vehicle's weight?
OA. Shock
OB. Idler arm
OC. Stabilizer link
OD. Spring

Answers

The component that supports a vehicle's weight is the spring.

What is the Spring?

The spring is responsible for absorbing the shock and weight of the vehicle, ensuring a smooth ride for the passengers. The idler arm is part of the steering system, while the stabilizer link helps to control the vehicle's sway and stability during turns.

The shock, on the other hand, helps to dampen the bounce and movement of the vehicle. While all of these components play a vital role in a vehicle's performance, it is ultimately the spring that bears the weight and keeps the vehicle stable on the road.

Read more about vehicles here:

https://brainly.com/question/28918094

#SPJ1

You suspect a problem with a file that is important to one of your installed applications. You are running Windows 7 64-bit edition. You have thoroughly checked the Program Files folder and cannot find the folder that holds this application. What might be the problem?

Answers

Answer:

Explanation:

There could be a few potential problems that could be causing the issue:

The application might not have been installed correctly, and the files are located somewhere else on the computer. In this case, you may need to search the entire computer or contact the application's support team for assistance.

The application may have been uninstalled, or the files could have been deleted or moved. If this is the case, you may need to reinstall the application or restore the files from a backup.

The application might not be compatible with Windows 7 64-bit edition, and therefore, the files may not be stored in the Program Files folder. In this case, you may need to check the application's documentation or contact the support team to determine where the files are located.

Overall, it is essential to troubleshoot the issue thoroughly and gather as much information as possible to determine the root cause of the problem.

Other Questions
a uniform rope hangs from a ceiling. without tugging on the rope, you give the bottom of the rope a wiggle and a wave travels upward along the rope. what can you say about the speed of the wave as the wave travels up the rope? Ben made a sundial in his backyard by placing a stick with height, 6 inch straight into the ground, and marking the hours in the grass. Can someone help please! What would be the average tax rate for a person who paid taxes if $5,040 on a taxable income of $42,000? Question 10Which equation represents the line parallel to the line whose equation is 4x+2) = 14 andpassing through the point (2, 2)?03=-2x+60y=-2xOy-x+12 ptsOy-x 1. Describe the four major theories of planned change.Four Theories:- Three-step Change Model.- Action Research Method- The Positive Model- The Continuous Change Model2. Explain the four activities that an organization uses to implement change.Four Activities:- Entering and Contracting- Diagnosing- Planning and Implementing Change- Evaluating and Reinforcing Change all the faces of the prism meet at right angles. the volume the prism is 490m cube. what is the surface area of the prism? Need this done fast. Help. the graph shows that you are traveling at a constant rate three of the statements are true, which is not which of the following are the characteristics of the industrial revolution in the 19th century,? select two correct answers? How old was Shakespeare when he died The following system of linear equations has how many solutions?3y = x + 66y - 2x = 12 Part B: Research on corporate governance characteristics on the selected two ASX listed companies. In this part, your investigation should cover at least the following research questions: 1. Identify and contrast how the two sample companies disclose their corporate governance strategies, policies, and practices. (i.e., approaches considered) 2. Identify and compute the following corporate governance indicators from the collected/ downloaded annual reports for the selected/respective two companies: a) Total number of directors (i.e., board size). b) Percentage of non-executive directors. c) Percentage of independent directors. d) The name of the Chief Executive Officer (CEO) and/or Chairman and the summary of his/her statement in the annual reports for the selected companies. e) Percentage of share hold by the executive directors. f) Percentage of shares owned by the block-holders and institutional investors. 3. Compare the corporate governance indicators of the selected two companies and discuss the effectiveness, strength, and adequacy of the corporate governance practices and principles adopted by these companies. can some please help me do the odds please show work Please help.......... what is the measure of angle DEB? 30,60,120,150 explanation . "No matter where the object is kept, a diverging lens always forms a virtual image" Do you agree? Give reasons. If X equals seven what is X times by 72 How do the historical details in this passage supportthe authors' claim?O The text includes parts of primary-sourceinterviews with enslaved people to illustrate thedifficulty of life on a sugar plantation in Louisiana.The text includes a secondary source to explainwhy the enslaved people on sugar plantationsworked seven days each week.O The text includes primary-source quotations toshow that religious beliefs eased the lives ofenslaved people on sugar plantations.O The text uses secondary sources to describeworking conditions in the sugar fields on theplantations across the American South. Which equation represents the relationship between x, the time in minutes, and y, the shots made?