Looking for extremely simple Python help

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

Looking for extremely simple Python help
  1. Unread #1 - Sep 16, 2018 at 9:07 AM
  2. Sad Boys
    Joined:
    Jul 31, 2018
    Posts:
    80
    Referrals:
    0
    Sythe Gold:
    127

    Sad Boys Member
    Banned

    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
     
  3. Unread #2 - Sep 16, 2018 at 7:59 PM
  4. bloody fear
    Joined:
    Jan 1, 2017
    Posts:
    436
    Referrals:
    0
    Sythe Gold:
    668
    Two Factor Authentication User MushyMuncher Potamus

    bloody fear Forum Addict
    $100 USD Donor New

    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.
     
    ^ Sad Boys likes this.
    Last edited: Sep 16, 2018
  5. Unread #3 - Sep 16, 2018 at 8:22 PM
  6. Sad Boys
    Joined:
    Jul 31, 2018
    Posts:
    80
    Referrals:
    0
    Sythe Gold:
    127

    Sad Boys Member
    Banned

    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.
     
  7. Unread #4 - Sep 16, 2018 at 9:52 PM
  8. bloody fear
    Joined:
    Jan 1, 2017
    Posts:
    436
    Referrals:
    0
    Sythe Gold:
    668
    Two Factor Authentication User MushyMuncher Potamus

    bloody fear Forum Addict
    $100 USD Donor New

    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 >

Users viewing this thread
1 guest


 
 
Adblock breaks this site