Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How would I make the following python program in Kotlin import random def main(): # Generate 200 random integers in the range 1 through 100

How would I make the following python program in Kotlin

import random

def main():

# Generate 200 random integers in the range 1 through 100 (inclusive)

numbers = [random.randint(1, 100) for _ in range(200)]

# Count the frequency of numbers in each range

# Initialize a list of 10 elements, representing each range (1-10, 11-20, ..., 91-100)

histogram = [0] * 10

# Loop through the list of numbers and increment the count for the corresponding range

for number in numbers:

# Calculate the index of the range by integer division

index = (number - 1) // 10

histogram[index] += 1

# Print the histogram

# First, print the header

print("Range # Found Chart")

print("-------- ---------- -------------------------------------------")

# Loop through each range and print its count and chart

for i in range(10):

# Calculate the low and high values for the current range

low = i * 10 + 1

high = low + 9

count = histogram[i]

# Generate the chart as a string of asterisks with the same length as the count

chart = "*" * count

# Print the current range, count, and chart

print(f"{low:2} - {high:2} | {count:2} | {chart}")

if __name__ == "__main__":

main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions