Question

In: Computer Science

In Python, write a program to get a positive integer n from keyboard first (your program...

In Python, write a program to get a positive integer n from keyboard first (your program must be able to check the validation of n being positive), and then get n integers from keyboard and store these n integers in a list. Do some processing, and print out average of the elements in the list at end of your program.

For example, suppose user enters 3 first (n = 3), which means we get another three integers from the user. Suppose these three integers are 1, 2, -6. Store them in a list. It is easy to see the list is [1, 2, -6], and average of the elements in the list is (1 + 2 - 6) / 3 = -1.

Solutions

Expert Solution

Below is the python code for mentioned problem statement:

# Program will start from here
if __name__ == '__main__':
    # User input
    count = int(input("How many numbers you want to enter : "))
    # Empty List
    list_num = []
    if count >0:
        # for loop to take user number for num
        for x in range(count):
            num = int(input("Enter the number : "))
            list_num.append(num)
        print("Average of elements : ", int(sum(list_num)/len(list_num)))
    else:
        print("Enter positive number. Try Again!")


Related Solutions

write a python program that inputs 10 integer values from the keyboard and then displays their...
write a python program that inputs 10 integer values from the keyboard and then displays their sum. use for loop
Write a C++ program that accepts a positive integer number from the keyboard . The purpose...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose of the program is to find and the display all the square pair numbers between 1 and that number. The user should be able to repeat the process until he/she enters n or N in order to terminate the process and the program. Square numbers are certain pairs of numbers when added together gives a square number and when subtracted also gives a square...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
Write a Python program to find the smallest positive integer that is a perfect square and...
Write a Python program to find the smallest positive integer that is a perfect square and it contains exactly three different digits.
Write, in Python, a recursive algorithm that takes, as input, a positive integer n, and returns,...
Write, in Python, a recursive algorithm that takes, as input, a positive integer n, and returns, as output, the sum of the first n positive odd integers. Your solution should be recursive, and it should not contain any "for" loops or "while" loops.
PYTHON Let n denote an integer entered by the user. Write a program to print n...
PYTHON Let n denote an integer entered by the user. Write a program to print n multiples of 5 in the descending order, with the last number being 5. Print the average of those n multiples
(C++) Write a nested loop that reads an integer n (n>0) from the keyboard and print...
(C++) Write a nested loop that reads an integer n (n>0) from the keyboard and print out "n" lines as follows: 0 0 1 0 1 2 0 1 2 3 … 0 1 2 3 … n-1
A. Write a program 1. Prompt the user to enter a positive integer n and read...
A. Write a program 1. Prompt the user to enter a positive integer n and read in the input. 2. Print out n of Z shape of size n X n side by side which made up of *. B. Write a C++ program that 1. Prompt user to enter an odd integer and read in the value to n. 2. Terminate the program if n is not odd. 3. Print out a cross shape of size n X n...
I have a python coding question: Write the function: eAapproximately (n), that takes a positive integer...
I have a python coding question: Write the function: eAapproximately (n), that takes a positive integer value n and returns an approximation of e as (1 + 1/n)^n I am not even sure what the question is asking me to do but I think it is asking me to code that function. Does anyone know how to do this?
JAVA Language: Write a program that prompts the user to enter a positive integer n (0...
JAVA Language: Write a program that prompts the user to enter a positive integer n (0 up to 232 -1). You must write a function that takes as input n and returns a string s representing the number n in binary. For this assignment, you must use the method of successive division by 2 to convert the number to binary. Your main program must print out s. Example: If the user enters the number 66, your program must print out...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT