Python Forum
programming homework - 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: programming homework (/thread-10044.html)



programming homework - propal - May-10-2018

anyone knows why this does not give me the shared letters properly?
#shared_positions = 0
#x = 0
#while True:
#    print('Enter two words of the same lenght')
#    word_1 = (input('Enter the first word: '))
#    word_2 = (input('Enter a second word: '))
#    l_word_1 = len(word_1)
#    l_word_2 = len(word_2)
#    sums = word_1 + word_2
#    if range(l_word_1) == range(l_word_2):
#        break
#    else:
#        print('The words have different sizes, please enter words of the same size.')
#
#for x in range(0, l_word_1):
#    if word_1[x] == word_2[x]:
#        shared_positions += 1 
#    print('They share {} at position {}.' .format(word_1[x], x))
#print('The total share of letters is ', shared_positions)



RE: programming homework - j.crater - May-10-2018

Please put your code in Python code tags, you can find help here. And remove the hashes, they make the code even more unreadable.


RE: programming homework - micseydel - May-10-2018

I edited the code to have code tags, although I didn't remove the hashes in spite of them making it harder to read. Is this the actual code you're running? Because if it is, the hashes make everything a comment and that's why it's not working. Otherwise, can you make more explicit what the expected vs actual output is?


RE: programming homework - wavic - May-11-2018

The printing the shared positions is outside the if block. It will print all word_1 letters and their positions because it executes at every iteration.

if range(l_word_1) == range(l_word_2) could be like this if l_word_1 == l_word_2


RE: programming homework - propal - May-11-2018

(May-11-2018, 05:39 AM)wavic Wrote: The printing the shared positions is outside the if block. It will print all word_1 letters and their positions because it executes at every iteration.

if range(l_word_1) == range(l_word_2) could be like this if l_word_1 == l_word_2

still does not work..


RE: programming homework - wavic - May-11-2018

How does not work? Did you remove all #? See @micseydel's post


RE: programming homework - cryomick - May-16-2018

I don't know if this is still open, but try moving the line
print('They share {} at position {}.' .format(word_1[x], x))
in to the "if" block