0
Possible to do a one liner???
POP SNAP CRACKLE SOLUTION one = int(input()) two = int(input()) three = int(input()) four = int(input()) five = int(input()) six = int(input()) list = [one, two, three, four, five, six] final = [] for i in list: if i%3 == 0: s = "Pop" final.append(s) elif i%2 == 1: s = "Snap" final.append(s) else: s = "Crackle" final.append(s) print(' '.join(final))
15 odpowiedzi
+ 3
print(*[("Pop","Snap","Crackle")[(0,1,2,0,2,1)[int(input())%6]]for _ in"Krispy"])
https://code.sololearn.com/cBl54mZ6XjsX/?ref=app
+ 2
Yes but you have got a code ugly as hell. I think is better optimize your code:
final =''"
For i in range(6):
val = int(input())
If val%3 == 0:
final = final + "Pop "
Elif val%2 == 0:
final = final + "Snap "
Else:
final = final + "Crackle "
print(final.rstrip())
+ 2
Rstrip trims final withespaces
+ 2
Not a one-liner, but easy to understand 😊
in_list = [input(), input(), input(), input(), input(), input()]
result = ""
for x in in_list:
if int(x) % 3 == 0:
result += "Pop "
elif int(x) % 3 != 0 and int(x) % 2 != 0:
result += "Snap "
else:
result += "Crackle "
print(result.rstrip())
+ 1
David Delgado my specialty lies in web-based coding, and it seems you are more experienced in data science than me, so no arguments here (-:
But to pick a little on your code, I would have done "final += string" instead of "final = final + string" to type less :D
But thanks for the feedback and your code, I adopted your way of taking the input() into the for loop - way better 😊👌 And also the .rstrip() instead of result[:-1]
0
David Delgado whats rstrip do? never encountered
Thanks for feedback
0
✩✮★✮✩ crazy cool, if it works,
Why whoudl crackle and snap be in the same position and with consitoon i%2 and how do we know the correct one will be printed ?
0
✩✮★✮✩ amazing
WhAt _ standss for ?
0
In my opinion is better don't store variables if you don't need it for the output and save memory reusing the same.
But it's not important in this case because is a little chunk of code.
0
It's only a way to manage the assignment because of the original C way. I never remember if += works in a language if I'm not in the IDE and try it first ;P
I prefer your way too.
0
Yeah I get that, and I see that many great coders stick to it either way. I was just picky for the fun of it ;D Buenas tardes amigo (-:
0
# shorter than ✩✮★✮✩
print(' '.join(['Pop','Crackle','Snap'][i%3]for i in map(int,input().split())))
0
Ervis Meta - SoloHelper good so far. Now fulfill the requirement to get six inputs.
0
Just insert how many numbers you want separated by spaces and it'll work no matter that.
0
Ervis Meta - SoloHelper yep, I like how you made that that work. Unfortunately, the Code Coach inputs come on separate lines.
Edit: I tried it in Code Coach and found that it didn't output the right sequence for Test Case 2: 100 200 300 150 250 350.