Python Forum
Need help explaining what the variables do in my code.
Thread Rating:
  • 3 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help explaining what the variables do in my code.
#4
(Jan-26-2017, 09:45 PM)micseydel Wrote:
(Jan-26-2017, 09:04 PM)BurnedChipotle Wrote:  have to do a write up explaining what my the variables are in my code and what they do, can somebody explain to me why am I using these certain variables or give me advice on what to write?
Please don't take this as an accusation, but when someone says something like this my first thought is, "they found this code online and need someone to explain it to them." At the very least, you should be asking more specific questions or making an attempt and asking us to point out problems with that attempt. Generally, we aren't going to do anyone's homework for them, even if they've already succeeded with part of that homework.

Also, metulburr is right that you should be using code tags but in any case your image link looks broken to me.
I understand what you mean, I can assure that I have written this coding in my lessons however now that I have moved on to the write up section I struggle with explaining it as I've only just started learning Python this year. I just need to know how the Position variable, which I now know is an Integer variable works in my code and also how the words=sentence.split(" ") variable works.

My coding is below

sentence=input ("type in the list you wish to be counted ").lower()

keyword=input ("enter the word to be searched ").lower()

words=sentence.split(" ")

position=1

for word in words:
     if word==keyword:
        print ("found at {0}".format (position))

     position=position+1


if not keyword in words:
     print ("Error: word was not found in list")
Reply


Messages In This Thread
RE: Need help explaining what the variables do in my code. - by BurnedChipotle - Jan-30-2017, 10:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Explaining "translate" method lummers 4 2,488 Jan-13-2020, 06:31 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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