[Tutor] for loop question
Jim
electrical at triad.rr.com
Sun Jul 1 23:50:12 CEST 2012
Hello Friends,
I apologize for being such a bother. This problem has been evading me
all day. Can you please give me a hint as to why I cannot put the
variable UpperCaseSentence outside of the for loop?
I can do it in other instances but not in this one.
Thank you so much,
Jim
#Main function.
def main():
mySentence = (input("Enter text."))
mySentenceList = mySentence.split('.')
#Call fixCase function. Send it mySentenceList and receive result
#and stores result in variable named output.
output = fixCase(mySentenceList)
print(output)
def fixCase(myList):
#Begin making a loop through the list, using a variable myString
for myString in range (len(myList)):
tempString = myList[myString] #Store in temporary variable.
myList[myString] = tempString[0:1].upper() +
tempString[1:len(tempString)] #Replace with upper
UpperCaseSentence = (myList[myString])
print(UpperCaseSentence)
#Call main function
main()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: electrical.vcf
Type: text/x-vcard
Size: 272 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20120701/164332a3/attachment-0001.vcf>
More information about the Tutor
mailing list