[Tutor] Fwd: Need help returning a null/blank value when using string indexes

Robyn Perry nybor.robyn at gmail.com
Wed Aug 28 04:41:49 CEST 2013


Hi,

This is my first time asking for help on this list, so I welcome
constructive criticism about how to make my question clearer. AND I'm
thankful that I found this list!

Here's my issue:

Below the line, I've copied and pasted an assignment. This isn't homework
-- it's practice on a Udacity (free online course) as I'm learning Python.
I've written it out and gotten it almost correct except for Test Case 3.
All the other problem sets give you the answers, but this one was suggested
from a student in the class and there was no given solution that I could
use to see where I'm going wrong.

Which brings me to you all.

The task asks me to assign something to variables part1, part2, and part3
using the given variables fragA, fragB, and fragC. Everything works except
that I can't seem to give part2 the right assignment to produce "Ucity".
I've gotten this far as an assignment for part2:

part2 = (fragA[-7:-5] + '')

But it asks me to use a string, not a blank space. part2 needs begin with
'da' so I can produce 'Udacity' in Test Case 2, but needs to somehow end
with a null kind of value so I can produce 'Ucity' in Test Case 3. See
below for the complete assignment, in comments, for more clarity in what's
going on:

(By the way, the commented out bit at the end is just my notes to help
steer me in the right direction).

_________________________________________________________

# Write one line of Python code that uses
# only the variables fragA, fragB, and fragC
# to satisfy the given test cases.
# If you are not sure how multiple assignments and
# string slicing works, check out the links to
# additional tutorials in Instructor Comments
# under this exercise!

fragA, fragB, fragC = 'supercalifragilisticexpialudacious', \
                      'SUPERMAN', 'ytiroirepus'

### WRITE MULTIPLE ASSIGNMENT HERE ###
### THIS MUST BE ONE LINE ###
part1, part2, part3 = fragB[1], (fragA[-7:-5] + ''), (fragA[5] + fragC[2] +
fragC[1] + fragC[0])

### TEST CASES. PRESS RUN TO TEST ###
deadline = part1 + part2[0:2] + part3[-1]
print "Test case 1 (Uday): ", deadline == 'Uday'
fixed = part1 + part2 + part3
print "Test case 2 (Udacity): ", fixed == 'Udacity'
destination = part1 + part2[-1] + part3
print "Test case 3 (Ucity): ", destination == 'Ucity'


#part1, part2, part3 = fragB[1], fragA[-7:-5], fragC[0]
#deadline
#part3 = ....y
#part2 = da
#part1 = U

#part1, part2, part3 = fragB[1], fragA[-7:-5], ('c' + fragC[2] + fragC[1] +
fragC[0])
#fixed
#part3 = city
#part2 = da
#part1 = U

#part1, part2, part3 = fragB[1], fragA[-7:-5], fragC[0]
#destination
#part3 = city
#part2 = da' '
#part1 = U

________________________

Thank you kindly!

Robyn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130827/6627e6d8/attachment.html>


More information about the Tutor mailing list