Adblock breaks this site

Looking for extremely simple Python help

Discussion in 'Programming General' started by Sad Boys, Sep 16, 2018.

  1. Sad Boys

    Sad Boys Member
    Banned

    Joined:
    Jul 31, 2018
    Posts:
    80
    Referrals:
    0
    Sythe Gold:
    127
    Looking for extremely simple Python help

    [​IMG]

    so I think first line should be

    person = input ()
    //then the second line
    print ""
    //followed by some other stuff but i'm not sure, tl;dr prof handed out python assignment we've never been taught python and it's not in cirriculum, can someone help me figure out this simple bit? Thanks, lmk if i'm wrong on how far I got so far, google was not my friend I tried lol
     
  2. bloody fear

    bloody fear Forum Addict
    $100 USD Donor New

    Joined:
    Jan 1, 2017
    Posts:
    436
    Referrals:
    0
    Sythe Gold:
    668
    Two Factor Authentication User MushyMuncher Potamus
    Looking for extremely simple Python help

    So the first line is correct.
    The second line (or lines) needs to take the person variable that you just created and figure out the first middle and last characters. Strings of text, like a name 'Jeremy' can be sliced, meaning that if you add bracets ( [ or ] ) after a string (or its variable) you can select a character in that position.

    So if person = 'Jeremy' and you execute the code 'person[0]' you'll get 'J', or the 0th element in the string (computers start counting at 0!)
    person[0] is the first letter.

    slicing the -1st element gives you the last letter of a string
    person[-1] is the last letter.

    What about the middle? You could do len(person) to find its length and divide by 2, then pass that into the slice (The int() function just removes the decimal place in case there's an odd number of digits:
    middle_element = int(len(person) / 2))
    person[middle_element]


    Let me know if you have any questions, I wrote this kind of hastily.


    edit:
    For your input line, why not do something like 'person = input('> ')
    This way, you're prompting the user to enter something and it's not just a black line
    You could also do 'person = input('Enter your name:\n> ')
    The '\n' represents a newline, so the '> ' will be on the next line.
     
    Last edited: Sep 16, 2018
    Sad Boys likes this.
  3. Sad Boys

    Sad Boys Member
    Banned

    Joined:
    Jul 31, 2018
    Posts:
    80
    Referrals:
    0
    Sythe Gold:
    127
    Looking for extremely simple Python help


    Thanks that really helped me understand stuff, and I got it working now God bless, gonna try a few more tutorials online when I'm less busy this really is a great language thanks mate have a great day cheers.
     
  4. bloody fear

    bloody fear Forum Addict
    $100 USD Donor New

    Joined:
    Jan 1, 2017
    Posts:
    436
    Referrals:
    0
    Sythe Gold:
    668
    Two Factor Authentication User MushyMuncher Potamus
    Looking for extremely simple Python help


    Np man, inbox me if you have any more questions down the road!
     
    Sad Boys likes this.
< Need some help ~micro chip | .Lua >


 
 
Adblock breaks this site