You don't need that MakingGraphic
, just use a list to store the strings of "*":
In [14]: howmany = int(input("How many numbers will you write?"))
...: lines=[]
...: for i in range(howmany):
...: number = int(input("Write a number "))
...: lines.append('*'*number)
...: print('\n'.join(lines))
The issue of your code is, variable "list" is an integer, not a list (don't use "list" as a variable name, because it shadows the python builtin type/function list
, use some name like lst
instead).
If you want to try function call, you can change your code to:
import math
def MakingGraphic(lst):
graphic = '\n'.join(number * '*' for number in lst)
return graphic
lst = []
howmany = int(input("How many numbers will you write?"))
for i in range(0, howmany, 1):
number = int(input("Write a number "))
lst.append(number)
result = MakingGraphic(lst)
print(result)