Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
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
  Issue with logic in homework fad3r 5 87 May-24-2018, 08:13 AM
Last Post: Larz60+
  Python clustering homework wjpython 3 116 May-11-2018, 07:57 PM
Last Post: j.crater
  Homework help JNG_123 1 115 Apr-07-2018, 09:02 AM
Last Post: Gribouillis
  Working with lists homework Otaku2 6 280 Apr-04-2018, 03:02 PM
Last Post: nilamo
  Homework: Invalid syntax using if statements chehortop 3 169 Mar-01-2018, 04:38 AM
Last Post: micseydel
  Working with lists homework (2) codellino 7 353 Feb-28-2018, 11:23 AM
Last Post: buran
  Homework help? manualbeatdrop 1 109 Feb-27-2018, 09:46 PM
Last Post: sparkz_alot
  Homework (counting iteration issue) Cardinal07 10 245 Feb-26-2018, 04:45 AM
Last Post: Larz60+
  Help with homework problem - iterating a function midnitetots12 4 215 Feb-21-2018, 10:51 PM
Last Post: nilamo
  python in JES homework question, lsteffen 1 160 Feb-11-2018, 05:52 PM
Last Post: Taco_Town

Forum Jump:


Users browsing this thread: 1 Guest(s)