• Log in or sign up for an account here: https://www.sythe.org/login

Looking for extremely simple Python help

Sad Boys

Member
Banned
Joined
Jul 31, 2018
Sythe Gold
127
Messages
80
Age
46
Looking for extremely simple Python help
o5yy4O4.png


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
 
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:
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.


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.
 
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.


Np man, inbox me if you have any more questions down the road!
 
Runescape Gamblingrunescape gambling
Back
Top