Skip to content

Question 27

After the user enters an integer n, the code is supposed to print out a list of integers from 1 to n that has at least one digit '8' in it inclusively. e.g., if the user input 30, the code should print:

[8, 18, 28]

Complete the code below by filling in the blanks. [5 marks]

1
2
3
4
5
6
7
n = int(input("Please enter a positive number: "))
lst = []
for i in range(___BLANK_1___):
    if ___BLANK_2___:
        lst.append(i)

print(lst)
Model Solution
1
2
3
4
5
6
7
n = int(input("Please enter a positive number: "))
lst = []
for i in range(1.n+1):
    if '8' in str(i):
        lst.append(i)

print(lst)
  • Blank 1: 1, n+1
  • Blank 2: '8' in str(i)