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

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 programming homework propal Unladen Swallow Posts: 2 Threads: 1 Joined: May 2018 Reputation: 0 Likes received: 0 #1 May-10-2018, 12:39 PM (This post was last modified: May-10-2018, 11:36 PM by micseydel. Edited 1 time in total. Edit Reason: Code tags. ) 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. j.crater Posts: 729 Threads: 21 Joined: Sep 2016 Reputation: 31 Likes received: 103 #2 May-10-2018, 12:43 PM Please put your code in Python code tags, you can find help here. And remove the hashes, they make the code even more unreadable. micseydel Knight Who Says Ni Posts: 1,287 Threads: 29 Joined: Sep 2016 Reputation: 26 Likes received: 373 #3 May-10-2018, 11:37 PM 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? wavic So-and-so of the Yard Posts: 2,408 Threads: 32 Joined: Sep 2016 Reputation: 71 Likes received: 271 #4 May-11-2018, 05:39 AM 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 propal Unladen Swallow Posts: 2 Threads: 1 Joined: May 2018 Reputation: 0 Likes received: 0 #5 May-11-2018, 07:16 AM (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.. wavic So-and-so of the Yard Posts: 2,408 Threads: 32 Joined: Sep 2016 Reputation: 71 Likes received: 271 #6 May-11-2018, 07:24 AM 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 cryomick Programmer named Tim Posts: 8 Threads: 1 Joined: Oct 2017 Reputation: 0 Likes received: 1 #7 May-16-2018, 11:12 AM 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 « Next Oldest | Next Newest »

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)