Python Forum

Full Version: enumerate and output control
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

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.
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'
OK, and what seems to be the answer?
Please post your code and the output you are expecting.
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?
(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?
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.
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?