1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lina2011 [118]
2 years ago
7

I have a bit of code, that creates an initial array and reads data into the array until the array is full, and resizes the array

, increasing its size. Then it calculates the sum of all the integers and calculates the average of all the integers. (keep reading for my question on this)
import random

dataSize = random.randint(1,200)
# Create a random array with data
data = []
for i in range(dataSize):
randomNum = random.randint(1, 100);
data.insert(i, randomNum)
#--------------------------------------------------------------------

# Our solution:
constant_size = 100
size = 100
accumulator = 0
pos = 0

# Fill up our array with 0s, 100 items.
newArr = [0] * size

def insert(value):
global size, pos, accumulator

if pos >= size:

size += constant_size

newArr.insert(pos, value)
pos = pos + 1
accumulator = accumulator + value


# Main method to load data
for i in data:
insert(i)

print(newArr)
print('Total items position:', pos)
print('Total items size:', size)
print('Sum:', accumulator)
print('Average:', accumulator/pos)
#----------------------------------------------------------------------

What I would like to know is how to make the program read a sequence of integers from stdin and store them in the array. Essentially what this means is it reads a file I give it that contains integers, and then stores them in an array, takes those integers from the file to calculate the sum of the elements in the array, and calculate the average of the elements in the array.

So far what I've come up with is to replace the whole first part that defines what the data equals, and write data = sys.stdin.read() so that it can take a file and read it.
Computers and Technology
1 answer:
mojhsa [17]2 years ago
6 0

Answer:

check you spelling I can see one already :(

You might be interested in
Leah deals with several file conversions every day.
Lelechka [254]
That’s not a question but good for her
5 0
3 years ago
True or False? Wireless connections that use a higher frequency are faster but have a shorter range.
Rudiy27

Answer:

it's a True statement

6 0
3 years ago
A web directory is a web page that conducts searches of the web to find the words or expressions that you enter? true or false.
Sav [38]
The answer to this is true! hope i helped!
4 0
3 years ago
Nhiệt độ chiết rót của máy chiết rót có van trượt là bao nhiêu
Delvig [45]

Answer:

please translate

Thank you✌️

6 0
3 years ago
We look for trends when we are looking at data. What is a trend?
yulyashka [42]
A subject of what people say at the time, most used, famous at the present time
4 0
3 years ago
Read 2 more answers
Other questions:
  • Marie uses a browser to visit a blog. What is the unique identifier of the blog? A. web page B. website C. web address D. email
    7·2 answers
  • Someone who is young, lacks funds, and really wants to gain technical skills while serving his or her nation should consider
    8·1 answer
  • A. True
    8·1 answer
  • You will be given a string, containing both uppercase and lowercase alphabets(numbers are not allowed).
    14·1 answer
  • Jane is creating a slide that will have a large heading and number of bullet points below it. What slide format should she use?
    12·1 answer
  • A TCP Sender is just about to send a segment of size 100 bytes with sequence number 1234 and ack number 436 in the TCP header. W
    5·1 answer
  • Hey, how is everyone????????????????????????????????
    8·2 answers
  • 41. All the following software are examples of operating systems EXCEPT
    5·1 answer
  • What is one disadvantage people face without a checking account?
    12·1 answer
  • Josh is learning about hackers known for causing damage and altering functions of websites. Which type of hacker is he learning
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!