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 :)
15 Respuestas
+ 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
+ 4
Max Lang
You might wish to look at a loop
+ 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
+ 2
Max Lang
Please identify which challenge in which course so I can look at it further
+ 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
+ 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?
+ 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.
0
But I cant use loop because its not an iteration
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)
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)
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)
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)
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))
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)
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!