how to change data in range?

Question:

how to change data in range?

e.g: i have N number. if x mutiple of a, change x to oke. if x mutiple of b, change x to nice. if x mutiple of c, change x to good.

N : 12
A : 2
B : 3
C : 4

1 Oke Nice OkeGood 5 OkeNice 7 OkeGood Nice Oke 11 OkeGoodNice

that’s my code

int_n = int(input('input N : '))
int_a = int(input('input A : '))
int_b = int(input('input B : '))
int_c = int(input('input C : '))

for i in range(1, int_n + 1) :
    if i / int_a == 0 :
        print('oke')
    if i / int_b == 0 :
        print('nice')
    if i / int_c == 0 :
        print('good')
    print()

i need help, thank you:))

Asked By: daylooo

||

Answers:

Try something like this:

N = 12
A = 2
B = 3
C = 4

lst = []
for x in range(1, N+1):
    if x % A == 0:
        lst.append('Oke')
    elif x % B == 0:
        lst.append('Nice')
    elif x % C == 0:
        lst.append('Good')
    else:
        lst.append(x)

result = ' '.join([str(x) for x in lst])
print(result)

Output:

1 Oke Nice Oke 5 Oke 7 Oke Nice Oke 11 Oke
Answered By: Naufal Hilmiaji
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.