153k views
5 votes
Write a MARIE program to calculate some basic statistics on a list of positive numbers. The program will ask users to input the numbers one by one. Assume that all numbers will be in the range 1 to 1000. To terminate the data entry, user will input any negative number. Once the data entry is complete, the program will show four statistics about the list of numbers: (1) Count (2) Minimum value (3) Sum of numbers (4) "Mean/Average" calculation.

As an example, if the user enters the following decimal numbers as input (one after the other)

23, 6, 78, 36, 3, 250, 127, 210, –5

the program would output the following values as the count, minimum, sum and mean respectively:

8
3
733
91

The average is calculated by dividing sum by count. Note that MARIE does not support floating point numbers, hence the result of division will only have the integer part (as shown in above example, average is 91 instead of 91.625)

A simple algorithm for implementing division in MARIE is shown below.

Let x = dividend, y = divisor, z = quotient (result) of division.

set initial z to 0
while x > y, do
set x to (x – y)
increase z by 1
endwhile

Assume that the user will always provide valid numbers as input, that is, do not worry about dealing with invalid input data.

Write comments within your program so that a reader can understand it easily.

User Elnaz
by
5.0k points

1 Answer

1 vote

Answer:

a=[23,6,78,36,3,250,127,210,-5]

i = len(a) # calculate length

j = min(a) # calculate minimun

k = sum(a) # calculate sum

l= sum(a)/len(a) # calculate mean

print(i)

print(j)

print(k)

print(l)

z = 0.0

i=0

x=[23,6,78,36,3,250,127,210,-5]

y = int(l)

while x[i] < y:

z= int(x[i]/y)

print(z)

x[i] = x[i] - y

z=z+1

i=i+1

Step-by-step explanation:

So above we have calculated Count, minimum, sum and mean/average. Also we did a simple division and printed quotient.

User Nemani
by
4.8k points