+ 4

Help plss!!

What’s it’s output and how I can identify? What is the output of this code? y=[x for x in range(10) if x//3==2] print(sum(y)) Sorry Doom Slayer I’m beginner :/

29th Jan 2024, 6:33 PM
Eloísa Mendonça Martins
Eloísa Mendonça Martins - avatar
18 Respuestas
+ 7
Welcome! Practice, learn, and don't give up!
29th Jan 2024, 7:21 PM
🇮🇱 Radin Masiha 🇮🇱
🇮🇱 Radin Masiha 🇮🇱 - avatar
+ 6
🇮🇱 Radin Masiha 🇮🇱 , the code that is executed has a for loop inside, but it is called a *list comprehension*.
29th Jan 2024, 9:15 PM
Lothar
Lothar - avatar
+ 5
Yes I think Python is one of the most useful languages, but you should think why are you learning programming first? What do you want to code!? Then choose your language depending on your aim. All in all, I suggest you to continue learning Pyrhon, and become an expert (enough). Then you can start other languages if neede.
29th Jan 2024, 8:04 PM
🇮🇱 Radin Masiha 🇮🇱
🇮🇱 Radin Masiha 🇮🇱 - avatar
+ 4
Nice, no problem. Here you've declared a variable called "y" and assigned it to a loop. You've defined "x" in range 10, which means whole numbers from 0 to 9. But there is a condition for it, you've said "x//3==2" which means those "x"es that the floor division of them equals to 2. So the numbers will be "6,7,8". Then you've printed the sum which outputs: 6+7+8=21 I'm not a Python expert, but I hope I was helpful. Any other questions? Don't hesitate to ask! (P.S. I'm not Doom Slayer, I am a Spartan 😄😄)
29th Jan 2024, 7:15 PM
🇮🇱 Radin Masiha 🇮🇱
🇮🇱 Radin Masiha 🇮🇱 - avatar
+ 4
The answer would be 21 because y = [6,7,8] y includes all the numbers that would result in 2 when floor divided by 3. Sum of all the numbers would be 21.
30th Jan 2024, 9:50 AM
Milad Hamidi
Milad Hamidi - avatar
+ 3
"Insert" your code here. Please don't expect us to guess your code
29th Jan 2024, 6:55 PM
🇮🇱 Radin Masiha 🇮🇱
🇮🇱 Radin Masiha 🇮🇱 - avatar
+ 3
What’s it’s output and how I can identify? What is the output of this code? y=[x for x in range(10) if x//3==2] print(sum(y)) Sorry Doom Slayer I’m beginner :/
29th Jan 2024, 7:00 PM
Eloísa Mendonça Martins
Eloísa Mendonça Martins - avatar
+ 3
And to add a tip, make sure you tag your relevant programming language (here Python) under your question.
29th Jan 2024, 7:20 PM
🇮🇱 Radin Masiha 🇮🇱
🇮🇱 Radin Masiha 🇮🇱 - avatar
+ 3
Eloísa Mendonça Martins , If you have some code, and you want to see what its output is, the first thing you should do is run it and look at the output. Do you need help about how to create a new program on Sololearn?
29th Jan 2024, 8:57 PM
Rain
Rain - avatar
+ 3
Thank you for all help! :)
30th Jan 2024, 9:00 AM
Eloísa Mendonça Martins
Eloísa Mendonça Martins - avatar
+ 2
Thank you! I will study more python, I’am very begginer in programming :)
29th Jan 2024, 7:20 PM
Eloísa Mendonça Martins
Eloísa Mendonça Martins - avatar
+ 2
Lothar, thanks for your information! I said I don't know Python 😅 But I may learn soon
29th Jan 2024, 11:46 PM
🇮🇱 Radin Masiha 🇮🇱
🇮🇱 Radin Masiha 🇮🇱 - avatar
+ 1
One question, do you know if the best programming language to learn from the beginning is Python, I'm learning the concept and how it works
29th Jan 2024, 7:23 PM
Eloísa Mendonça Martins
Eloísa Mendonça Martins - avatar
+ 1
Who can write code that removes the marker from the photo
30th Jan 2024, 10:23 PM
Виталик Савченко
+ 1
21 easy bruh
31st Jan 2024, 2:48 PM
Elyor Khaitov
Elyor Khaitov - avatar
+ 1
Elyor Khaitov , If your reply was to Bdhz Hzhd , don't bother, because all they did was copy and paste the opening message of the thread creator. They weren't asking a real question. And Milad Hamidi already said it was 21 and explained why anyway.
31st Jan 2024, 4:06 PM
Rain
Rain - avatar