- 1

what is the output for the following lines of code

1. for i in [0,2,3]: if i%2 == 0: print("even") elif i%2 !=0: print("nil") else: print("odd") 2. If we execute the expression foo = 'abc' * 10 what is the result? 3. x = "" while x != "xx": x += "x" print(x) 4. def f(u,y=[]) for I in range(u): y:append(i*i) Print(y) f(6) f(6, [4,1,5]) f(6) Hello, everyone, I need your kind solution and explanation on the above questions. thanks

8th Jun 2022, 2:21 PM
Adewale Olayiwola
Adewale Olayiwola - avatar
4 Answers
+ 1
have you tried running them yourself??? question 2 is very simple and question 4 have syntax error in it looks like homework
8th Jun 2022, 3:06 PM
Apollo-Roboto
Apollo-Roboto - avatar
+ 1
the problem here is that if we just give you the solution, we don't know if you'll learn from it... For the 1st question, you have a for loop going through an array of 0, 2, 3. i%2 == 0 is an easy way to check if a number is even. Try to run the code yourself for the output Question 2 is about the effect of the multiplication operation on a string. Again, try to run it yourself, why are you even asking this one... Question 3 is is a while loop apending a string to a string until it matches the while condition. Try running this one yourself and play with the values to understand what is happening better. Question 4 is a function f that appends a bunch of number to the given array. There is a syntax error as y:append should have a dot instead of a colon y.append. Run it yourself and if this one is harder to understand, you should revisit the functions lesson. With all of that said, No I won't give you the result of these codes, they are simple enough for you to find them yourself. I hope this will help.
9th Jun 2022, 12:29 AM
Apollo-Roboto
Apollo-Roboto - avatar
+ 1
Adewale Olayiwola If you just ran the codes, you'd see the results way faster and clearer. And would have a chance to experiment and learn. By doing nothing but waiting for a complete solution from someone else, you learn how not to learn. That's why we give information, directions, hints, etc., and refuse to solve everything for you.
9th Jun 2022, 5:07 AM
Emerson Prado
Emerson Prado - avatar
0
Thanks, Apollo for your kind response. it is homework I will find it difficult to get an answer to these questions. I really needs solution to it.
8th Jun 2022, 11:34 PM
Adewale Olayiwola
Adewale Olayiwola - avatar