def num():
while True:
n= int(input("donnez le num"))
if n > 0:
break
T=([int]*n)
for i in range (0,n):
n[i]=i
num()
print(T)
The code is mainly about creating a table after asking the user a number in this table i want to fill it with number and descending example: the user puts 10 desired result:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
CodePudding user response:
couple of issues in your code
- your code is not returning any value , so T is not defined outside of function
n[i]
meant to beT[i]
- you need to change the range to n 1
- you can shorten/optimize your code as follows
so:
def num():
while True:
n= int(input("donnez le num"))
if n > 0:
break
return [i for i in range(0,n 1)]
print(num())
et voila, output:
donnez le num 10
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]