Python Forum
enumerate and output control
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
enumerate and output control
#1

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.
Reply
#2
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'
Reply
#3
OK, and what seems to be the answer?
Reply
#4
Please post your code and the output you are expecting.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#5
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?
Reply
#6
(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?
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#7
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.
Reply
#8
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Alternative of this mini code without Enumerate and join function. Ace4Benji 2 2,475 Mar-09-2020, 08:22 PM
Last Post: micseydel
  Code Review: Range and Enumerate lummers 2 2,100 Jan-11-2020, 12:40 AM
Last Post: lummers
  How to transform an enumerate object into a dictionary fad3r 7 4,629 Feb-11-2018, 11:42 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020