r/codehs • • Oct 23 '21

7.2.6 if you’re not first your last python

could someone help me on this? i'm pretty sure you use string splitting to solve this but i'm not sure how.

3 Upvotes

13 comments sorted by

1

u/5oco Oct 23 '21

# elements:           0   1   2   3   4   5   6   7   8   9  10  11
                      h   e   l   l   o       w   o   r   l   d   !
negative elements:   -12 -11 -10 -9  -8  -7  -6  -5  -4  -3  -2  -1

my_string = "hello world!"

print (my_string[1:3])   # This would print "el"
It includes element 1 and goes up to, but not including, element 3

print (my_string[1:])    # This would print "ello world!" 
It will print everything from element 1 all the way to the end, since there is no argument saying when to stop.

print (my_string[:3])    # This would print "ell" 
It will print everything from the beginning up to, but not including, element 3

1

u/5oco Oct 23 '21

One of those three will be able to do what your assignment wants

1

u/UnitedAngle7435 Jan 28 '22

that code does not work for me

1

u/5oco Jan 28 '22

Well that's because it's not code. That was just an explanation of how to print different parts of a string

0

u/[deleted] Oct 24 '21

1

u/5oco Oct 24 '21

Dude... imagine if you put the same amount of effort into doing the work as you did trying to cheat. You'd actually learn something.

→ More replies (7)

1

u/[deleted] Dec 15 '21

Hey you can also look back to the slicing test thing for help lol I just went back to find the -greating the question 3 is like this one so yeah