How can I make a function that prints a histogram based on a list index (with more details inside)?


Mark Batista

So, I found this exercise.

Define a procedure histogram() that takes a list of integers and prints a histogram to the screen. For example, histogram([2, 1, 3]) should print the following:

XX

X

XXX

But I can't. I'm trying to write an algorithm that reads the length of a list independently of the length of the list. (meaning you can enter a list with 1, 2 or any number of objects)

Schultz

Simple histogram program that takes a list of inputs from the user and prints the histogram output.

def histogram(list):
        for x in range(0,len(list)):
                print('X' * list[x])
        return
li=[int(x) for x in input().split()]
histogram(li)

Related


How can I make this function more precise?

Nessel I'm a beginner and I made a function to calculate the length of a semicircular infinite serpentine figure. I accept two arguments. One of the radii is the initial circle, the second is the precision (i.e. the number of semicircles). Here's a schematic o

How can I make this function more precise?

Nessel I'm a beginner and I made a function to calculate the length of a semicircular infinite serpentine figure. I accept two arguments. One of the radii is the initial circle, the second is the precision (i.e. the number of semicircles). Here's a schematic o

How can I make this function more precise?

Nessel I'm a beginner and I made a function to calculate the length of a semicircular infinite serpentine figure. I accept two arguments. One of the radii is the initial circle, the second is the precision (i.e. the number of semicircles). Here's a schematic o

How can I make this function more precise?

Nessel I'm a beginner and I made a function to calculate the length of a semicircular infinite serpentine figure. I accept two arguments. One of the radii is the initial circle, the second is the precision (i.e. the number of semicircles). Here's a schematic o

How can I make this function more precise?

Nessel I'm a beginner and I made a function to calculate the length of a semicircular infinite serpentine figure. I accept two arguments. One of the radii is the initial circle, the second is the precision (i.e. the number of semicircles). Here's a schematic o

How can I write a method that prints out the histogram?

Ayoshna I have to write this program for the lab. I have to basically explain exactly what is a hashmap (keys and values) and declarations, basic operations of .add(), .get(), and how to get keys and values from a map. You can then use the woodchucks.txt input

How can I make a list based on this data?

Kyle Mann 所以我有下表,我如何快速列出带有配对值的总数,所以请看这个: 并将其更改为: 这样我就可以按总数对列表进行排序并找出哪个值的点数最多,实际表将包含更多数据。 谢谢你,凯尔。 西蒙·詹森 一种方法是尝试选择您想要从“行到列”的所有数据。将其粘贴到您想要的位置,但选择“选择性粘贴”。选择“转置”选项,然后单击“确定”。 还可以观看此视频等: https://www.youtube.com/watch?v=uV4CvGR6w7E

How can I make this histogram in ggplot/R?

Crimea Please find My data qbelow . I have two covariates: q$Studieand q$best.respcorresponding to each of the five different studies reporting the best response after a certain treatment. q$best.respThere are three levels table(q$best.resp) 0 1 2 62 42

How can I make this histogram in ggplot/R?

Crimea Please find My data qbelow . I have two covariates: q$Studieand q$best.respcorresponding to each of the five different studies reporting the best response after a certain treatment. q$best.respThere are three levels table(q$best.resp) 0 1 2 62 42

How can I make this match list code more efficient?

DarkDrassher34 I have two lists. I want to get the matching index. I came up with the following to illustrate: a = [1,2,6,5,3,4] b = [1,3,4,2,5,6] for i in range(len(a)): for j in range(len(b)): if b[j] != a[i]: next else:

How can I make this PHP function more efficient at scale?

frank fortress I don't know how to be more efficient and am struggling with coding challenges. Any tips? The purpose is to return unique values in an array. The test condition where the code fails function solution($A) { foreach ($A as $key => $value) {

How can I make this recursive function more efficient?

programmer I created this function to recursively copy an entire directory from an FTP server. It works fine, it's just that it's about 4 times slower than doing the same with FileZilla. It takes about 55 seconds to download a directory in FileZilla, but 229 s

How can I make this simple function more efficient?

quantum method I have salary data, about 95% of it is given in hourly format, but some of it is given in annual salary format. So I made a function to convert annual salary to hourly, but it takes 1 minute 40 seconds to run, when my dataset is 43000 rows x 12

How can I make this simple function more efficient?

quantum method I have salary data, about 95% of it is given in hourly format, but some of it is given in annual salary format. So I made a function to convert annual salary to hourly, but it takes 1 minute 40 seconds to run, when my dataset is 43000 rows x 12