The program should work as follow:
JavaScript
x
7
1
Please type in a number: 5
2
1
3
5
4
2
5
4
6
3
7
My code doesn’t do the same. I think there is should be the 2nd loop, but I don’t really understand how can I do it. Could you possibly give me a hint or advice to solve this task. Thanks. My code looks like this:
JavaScript
1
10
10
1
num = int(input("Please type in a number:"))
2
n=0
3
while num>n:
4
a = num%10
5
num -= a
6
num = num/10
7
print(a)
8
n = n + 1
9
print(n)
10
Advertisement
Answer
This should work:
JavaScript
1
7
1
num = int(input("Please type in a number:"))
2
number_list = [i+1 for i in range(num)]
3
4
while number_list:
5
print(number_list.pop(0))
6
number_list.reverse()
7