Design a program that asks the user to enter a series of 20 numbers. The program should store the numbers in an array and the display the following data: • The lowest number in the array • The highest number in the array • The total of the numbers in the array • The average of the numbers in the array

## Recommended Answers

You need to post an attempted effort before anyone will help you with homework.

just to help you,
- declare a counter = 0,
- array of numbers = [],
- while counter < 20
- take input from users
- array.append(input)
- print the array
- use min function to find lowest number in array
- use max function to find greatest number …

I'm new too (couple months), but you have to write code, not forever think about what might work.

Try something, get it to work, then try the next thing.

For instance write the code to ask the user to input a list of 20 integers. Make that work, then try …

## All 11 Replies

You need to post an attempted effort before anyone will help you with homework.

ok... I have no idea where to start with this. I mean I can do comments, but other than that I'm lost on arrays.

just to help you,
- declare a counter = 0,
- array of numbers = [],
- while counter < 20
- take input from users
- array.append(input)
- print the array
- use min function to find lowest number in array
- use max function to find greatest number in array
- use SUM function to find sum
- divide the sum by 20 to get the average.

• declare a counter = 0,
• array of numbers = [],
• while counter < 20
• take input from users
• array.append(input)
• print the array
• use min function to find lowest number in array
• use max function to find greatest number in array
• use SUM function to find sum
• divide the sum by 20 to get the average.

thanks alot, thats what I need, a place to start.The problem I'm having is that it has to be a string of 20 integers, how will it recognize or count the integers? Can I have it make an error if the integers aren't sepereated by a ,?

I'm new too (couple months), but you have to write code, not forever think about what might work.

Try something, get it to work, then try the next thing.

For instance write the code to ask the user to input a list of 20 integers. Make that work, then try the next step of analyzing the numbers. Post here (post the code) when you get stuck. Or if it's easier for you, write the code to do the analysis and hard code the 20 integers. Get that to work, then write the input part. Once both are done, combine them, substituting the input 20 integers for the hard coded 20 part.

But ya gotta write something first !

thanks alot, thats what I need, a place to start.The problem I'm having is that it has to be a string of 20 integers, how will it recognize or count the integers? Can I have it make an error if the integers aren't sepereated by a ,?

if you would use raw_input to enter, it gets stored as string

literally, you don't have to worry in python for such type conversions

you try something, i have the code ready with me..

This does something similar to what you want. Try to read each line and understand them they are pretty easy to follow.

``````print "Enter 5 numbers: "

numbers = []
for i in range(5):
numbers.append(int(raw_input("Enter number " + str(i + 1) + ": ")))

print "The lowest number is " + str(min(numbers))
print "The highest number is " + str(max(numbers))
print "The sum the numbers is " + str(sum(numbers))
print "The average the numbers is " + str(sum(numbers)/len(numbers))
``````

i want the user to enter the 20 numbers in one line opposed to asking them 20 times how I have it in this loop. I don't know if I need the user to separate the numbers by commas or not.

``````import java.util.Scanner;

public class NumberAnalysis

public static void main(String[] args)
{
Scanner keyboard = new Scanner( System.in );
int[] nums = new int;

for( i = 0; i < 20; i++ )
{
System.out.println( "Enter a series of 20 numbers:" );
nums[i] = keyboard.nextDouble();

}
for( i = 0; i < 20; i++ )
{
System.out.print( nums[i] + " " );
}
System.out.println();
}
}
``````

Editor's note ...
oops, you better ask this in the Java forum!

it's compling and running in my jGrasp program. It's just not written correctly for what I'm trying to do

I think we better consider the original problem solved

Evening Community!

Alright. As you can see I am "newbie" on the block. When I try approaching my professor for assistance she tells me to go to my book. But I digress. If I was able to use a while loop this would be more simplified. But our professor is asking us to use a FOR loop and we have to use 2 functions.

Per instruction:

``````#get_values -  takes one argument (a number) that indicates the list,gets the user input for a list of numbers,
# and returns the list of numbers. Use a for loop.

# do_analysis – takes one argument that is a list of numbers,
# then calculates and displays the statistical data specified
# by the problem. Hint: you may find built-in functions useful.
``````

Alright, easy enough. So below is my code but unfortunately I am getting back the awful " print ("The lowest number is: ") + str(min(numbers))
TypeError: 'module' object is not iterable

I am sure it is something I completely overlooking but any step in the right direction would be awesome. Thanks!

``````import numbers

def main ():
# create empty list
intro()
numbers = get_values()
get_values()
do_analysis()
input("press enter to continue.") # required

def intro ():
# explanation of program
print ("This program will get 20 numbers from you.")
print ("Once all numbers have been entered the program")
print ("will then analyze the data and display lowest number,")
print ("highest number, total, and average.")
print ("Alright! Let's begin.")
print ("-------------------------------------------------------")

def get_values():
values =[]
# get numbers and add to list
for i in range(20):
value =(int(input("Enter a number " + str(i + 1) + ": ")))
values.append(value)
return values

def do_analysis ():
print ("The lowest number is:  ") + str(min(numbers))
print ("The highest number is:   ") + str(max(numbers))
print("The sum the numbers is:  ") + str(sum(numbers))
print ("The average the numbers is:  ") + str(sum(numbers)/len(numbers))
``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.