Python Forum
enumerate and output control - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: enumerate and output control (/thread-5830.html)



enumerate and output control - atux_null - Oct-23-2017


Hi i have a homework where the folowing snippet has been given
foo='AB'
for i,k in enumerate(foo):
    for x in foo:
        print(___,end='')
It asks to replace ___ with i, k,x and a number to have as output 'AB'.
I am stuck, please.
i came to a point where it prints "ABAB" but it is not acceptable.


RE: enumerate and output control - lefkimi13 - Oct-24-2017

i have the same problem.....but i think ask to replace with two of three names i,k,x and a operator between them to have as output 'AB'


RE: enumerate and output control - atux_null - Oct-24-2017

OK, and what seems to be the answer?


RE: enumerate and output control - sparkz_alot - Oct-24-2017

Please post your code and the output you are expecting.


RE: enumerate and output control - atux_null - Oct-24-2017

Hi. The code is posted in my post #1 that i openened this thread. The output expected is a single word 'AB', already been stated in my original post. Could you be so kind and help us please?


RE: enumerate and output control - sparkz_alot - Oct-24-2017

(Oct-24-2017, 04:12 PM)atux_null Wrote: The code is posted in my post #1 that i openened this thread.

If that is your code, you would not have gotten "ABAB", in fact that code would not even run:

Error:
Traceback (most recent call last):   File "C:/Python/Math/scratch.py", line 28, in <module>     print(___, end='') NameError: name '___' is not defined
I would suggest you first add some print()'s so you can see what's actually happening with i, k and j. You say you are also supposed to use a number. Where is that?


RE: enumerate and output control - atux_null - Oct-24-2017

thanks a lot for the quick reply. in the print it has a part with ___. that needs to get replaced with 2 letters from i,k,x and a number, so that the output will be AB.
it is a given exercise and all we have to do is replace ___ with eg i,3,k and have output AB. But we cannot find which sequence is correct.


RE: enumerate and output control - Mekire - Oct-24-2017

As your (I'm assuming) classmate said:
Quote:replace with two of three names i,k,x and a operator between them to have as output 'AB'
What operator would it be?  What value does i have each iteration and what are the results of doing math with strings?