0

Snap crackle and pop

Hello, I am trying to do this challenge but im blocked (if you can guide me in tje right direction without giving me the full answer it would be great :) ) Here is my code : i=int(input()) sound = [] if i%3==0: sound.append("pop") elif i%2!=0: sound.append("Snap") else: sound.append("Crackle") print(sound) My problem is that it print only the first word and stop there, its like my whole programm stop after the first input. I dont really understand why, any help ? Thank you :)

6th Jun 2022, 4:29 PM
Max Lang
Max Lang - avatar
15 Antworten
+ 5
Do you mean by it only appends 1 word to the list which then prints that out only? If so, it's because you are using if elif else which means the first condition that is met will be activated but will ignore the rest. Tell me if I'm wrong thx
6th Jun 2022, 4:45 PM
Da GD Bot
Da GD Bot - avatar
+ 4
Max Lang You might wish to look at a loop
6th Jun 2022, 6:46 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
You're asking for one input. You'll need to find the sound effect for 6 numbers. You can try input().split() which essentially turns your input into a list. Empty. split() means your list will have n+1 number of substrings out of your input string, where n is the number of space char in your input string. (try to print it to see) so it's only after this that you can convert element type to integer by some function iterating over your list. or, you put int(input()) into a loop until you get all 6 numbers
7th Jun 2022, 10:38 PM
Korkunç el Gato
Korkunç el Gato - avatar
+ 2
Max Lang Please identify which challenge in which course so I can look at it further
7th Jun 2022, 9:44 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Da GD Bot yes its exactly that ! Great thank you ! I will look in this direction, I guess if I use a function it might works ? Thanks
6th Jun 2022, 5:19 PM
Max Lang
Max Lang - avatar
+ 1
Yes you can, Rik was right to suggest you so :-) What's the action you want to repeat? Will you be referring to this action later on? Does it need a name? How many times do you need to repeat it?(the answer to this is your iterable) What do you compare in your conditionals?
8th Jun 2022, 12:34 AM
Korkunç el Gato
Korkunç el Gato - avatar
+ 1
def sound(a): if a%3==0: return "Pop " elif a%2!=0: return "Snap " else: return "Crackle " for i in range(6): n=int(input()) print (sound(n)) #This will do your job.
8th Jun 2022, 3:48 PM
Suprio Paul
Suprio Paul - avatar
0
But I cant use loop because its not an iteration
7th Jun 2022, 6:31 PM
Max Lang
Max Lang - avatar
0
i=int(input()) sound = [] do(i) { if i%3==0: sound.append("pop") elif i%2!=0: sound.append("Snap") else: sound.append("Crackle") print(sound) }while(i<=6)
22nd Nov 2022, 4:18 PM
Anita chaubey
Anita chaubey - avatar
0
i=int(input()) sound = [] do(i) { if i%3==0: sound.append("pop") elif i%2!=0: sound.append("Snap") else: sound.append("Crackle") print(sound) }while(i<=6)
22nd Nov 2022, 4:18 PM
Anita chaubey
Anita chaubey - avatar
0
i=int(input()) sound = [] do(i) { if i%3==0: sound.append("pop") elif i%2!=0: sound.append("Snap") else: sound.append("Crackle") print(sound) }while(i<=6)
22nd Nov 2022, 4:18 PM
Anita chaubey
Anita chaubey - avatar
0
i=int(input()) sound = [] do(i) { if i%3==0: sound.append("pop") elif i%2!=0: sound.append("Snap") else: sound.append("Crackle") print(sound) }while(i<=6)
22nd Nov 2022, 4:18 PM
Anita chaubey
Anita chaubey - avatar
0
Here my Solution. I think it can also be more elegant, but it works q=int(input()) w=int(input()) e=int(input()) r=int(input()) t=int(input()) z=int(input()) c=list() b=[] text=[q,w,e,r,t,z] for i in text: if i%3==0: b='Pop' elif i%3>0 and i%2==0: b='Crackle' else: b='Snap' for n in range(1): c.append(b) print(" " . join(c))
9th Feb 2023, 5:11 PM
Michael Nazar Bogdan
Michael Nazar Bogdan - avatar
0
out = "" for x in range(6): i = int(input()) if i % 3 == 0: out += "Pop " elif i % 3 != 0 and i % 2 != 0: out += "Snap " else: out += "Crackle " continue print(out)
22nd Mar 2023, 6:44 AM
OneEleven
OneEleven - avatar
0
x='' for y in range(6): i=int(input()) if i%3==0: x+='Pop ' elif i%2==0: x+='Crackle ' else: x+='Snap ' print(x) #You can try this solution!
8th Jun 2023, 11:06 AM
Michael Ivanov
Michael Ivanov - avatar