Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
programming homework
#1
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)
micseydel wrote May-10-2018, 11:36 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Quote
#2
Please put your code in Python code tags, you can find help here. And remove the hashes, they make the code even more unreadable.
Quote
#3
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?
Quote
#4
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote
#5
(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..
Quote
#6
How does not work? Did you remove all #? See @micseydel's post
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote
#7
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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Homework help abdullahali 4 63 Sep-17-2018, 05:19 PM
Last Post: wavic
  HOMEWORK HELP abdullahali 1 90 Sep-17-2018, 06:58 AM
Last Post: Mekire
  Basic Programming Help Travisbulls34 3 121 Sep-11-2018, 06:12 PM
Last Post: gruntfutuk
  Homework Problem Travisbulls34 1 78 Sep-11-2018, 04:04 PM
Last Post: ichabod801
  Homework blabla44 3 212 Aug-20-2018, 11:45 AM
Last Post: ichabod801
  Homework on addition with working paperplanexx 1 148 Aug-19-2018, 12:40 PM
Last Post: j.crater
  yet another homework question HakolYahol 14 425 Aug-16-2018, 06:49 PM
Last Post: Larz60+
  i've got these very simple homework HakolYahol 7 249 Aug-12-2018, 10:18 AM
Last Post: HakolYahol
  Homework Help - Simple Grading System Segovia 7 408 Jul-24-2018, 10:55 PM
Last Post: Segovia
  from List to BeautifulSoup , Homework RPC 6 327 Jul-03-2018, 12:17 AM
Last Post: snippsat

Forum Jump:


Users browsing this thread: 1 Guest(s)