Here is my assignment with the directions. ###Programmer Brian Austin
###FOP
###3/30/09
###Assignment 8
###Using a loop, allow the user to input as many student names as they like and store the names in a list. in title format
#then write the list of names to a file named NAMES.
#Read your file back into a list and sort the list.
#Write the sorted list to a different file named SORTEDNAMES.
#Read in and print (on the screen) all the names of the SORTEDNAMES file.
#Add logic to handle file I/O error exceptions. You should include ALL I/O operations inside exception handling (open, read, write and close)

import cPickle
any_listnames=open("NAMES.TXT","w")
NAMES_list=["John", "Mary","Scott","Curly","Moe","Jon Doe"]
NAMES_file.close()
NAMES_list=cPickle.load(NAMES.file)

anylistnames=(raw_input("Enter as many student names as you have"))

print ("\nReading the entire file into a list.")
for line in anylistnames:
print line


try:
name= int(raw_input("Enter a name"))
except:

def _init_(names):


any_listnames=(NAMES.readlines.sort())
any_listnames.writelines(NAMES.title())
NAMESfile=open("NAMES.txt","r")
all_the_data=NAMES.read()
NAMES.close()
textfile = open("NAMES.txt", "r")
all_the_data=anyNAMES.read()
NAMES.close()
lines = NAMES.readlines()
print lines
print len(lines)
for line in lines:
print line
NAMES.close()
print "Opening and closing the file."
anylistnames= open("names.txt", "r")
namesfile.close()
print "\nReading the entire file at once."
anylistnames_file = open("names.txt", "r")
whole_thing = names_file.read()
print whole_thing
namesfile.close()
for line in any_files:
print line
anylistnames.writelines(NAMES_file.title())
anyNAMESfile=open("names.txt","r")
all_the_data=any_namesfile.read()
anyNAMESfile.close()


try:
name= int(raw_input("Enter a name"))
exce[t(ValueError),e:
print "Data entered was not a name", e
else:
print "The value of name is", name


i think it is because i don't have () in some areas.. can you fix it?

also I have another assignment..here it is..
here is the assignment directions:
Create a class named wpoMath. The class must contain the following:
1.) A constructor method that allows the calling program to specify a name for the object created, and then prints the object's name and a welcome message.
2.) Code "get" and "set" methods to retrieve and set the value of a property named "name" that reflects the object's name.
3.) Code a method named "plus" that adds a number to itself. It should respond with the answer in a property named "doubled."
4.) Code a method named "times" that multiples a number by itself. It should respond with the answer in a property named "squared".
5) Now, write the code that uses the wpoMath class to create an object. Then ask the user to supply a number. Use you object to print the object's name,the input number doubled, and the input number squared. I think I am missing the command to ask the user to supply a number ..but can you check for me?

#creating a Class
#

class wpoMath(object):
"""This is a Math object"""

#main program
wpoMath1=wpoMath()
wpoMath1.talk()
def _init_(self,wpoMath):
print "I am wpoMath object"
self.name = wpoMath
print wpoMath1.wpoMath
def _str_(self):
print "Hi, I'm, wpoMath, "\n"
self._wpoMath=wpoMath
def get_wpoMath(self):
return self._wpoMath
def _init_(self, plus):
self.plus = plus
def _str_(self):
doubled = self.plus + 1
return doubled
def _init_(self,times):
selftimes = times
def _str_(self):
squared = self.times * self.times
return squared
wpoMath = WpoMath()
wpoMath.talk()
def _init(self.wpoMath):
print self.name
print doubled
print squared

Please use code tags with your code to preserve the indentations. Otherwise the code is very difficult to read and not too many folks will help.

[code=python]
your Python code here

[/code]

Start with just this part and post the code here.

Using a loop, allow the user to input as many student names as they like

###Programmer Brian Austin
###FOP
###3/30/09
###Assignment 8
###Using a loop, allow the user to input as many student names as they like and store the names in a list. in title format
#then write the list of names to a file named NAMES.
#Read your file back into a list and sort the list.
#Write the sorted list to a different file named SORTEDNAMES.
#Read in and print (on the screen) all the names of the SORTEDNAMES file.
#Add logic to handle file I/O error exceptions. You should include ALL I/O operations inside exception handling (open, read, write and close)

import cPickle
any_listnames=open("NAMES.TXT","w")
NAMES_list=["John", "Mary","Scott","Curly","Moe","Jon Doe"]
NAMES_file.close()
NAMES_list=cPickle.load(NAMES.file)

anylistnames=(raw_input("Enter as many student names as you have"))

print ("\nReading the entire file into a list.")
for line in anylistnames:
print line


try:
name= int(raw_input("Enter a name"))
except:

def _init_(names):


any_listnames=(NAMES.readlines.sort())
any_listnames.writelines(NAMES.title())
NAMESfile=open("NAMES.txt","r")
all_the_data=NAMES.read()
NAMES.close()
textfile = open("NAMES.txt", "r")
all_the_data=anyNAMES.read()
NAMES.close()
lines = NAMES.readlines()
print lines
print len(lines)
for line in lines:
print line
NAMES.close()
print "Opening and closing the file."
anylistnames= open("names.txt", "r")
namesfile.close()
print "\nReading the entire file at once."
anylistnames_file = open("names.txt", "r")
whole_thing = names_file.read()
print whole_thing
namesfile.close()
for line in any_files:
print line
anylistnames.writelines(NAMES_file.title())
anyNAMESfile=open("names.txt","r")
all_the_data=any_namesfile.read()
anyNAMESfile.close()


try:
name= int(raw_input("Enter a name"))
exce[t(ValueError),e:
print "Data entered was not a name", e
else:
print "The value of name is", name

###Programmer Brian Austin
###FOP
###3/30/09
###Assignment 8
###Using a loop, allow the user to input as many student names as they like and store the names in a list. in title format
#then write the list of names to a file named NAMES.
#Read your file back into a list and sort the list.
#Write the sorted list to a different file named SORTEDNAMES.
#Read in and print (on the screen) all the names of the SORTEDNAMES file.
#Add logic to handle file I/O error exceptions. You should include ALL I/O operations inside exception handling (open, read, write and close)

import cPickle
any_listnames=open("NAMES.TXT","w")
NAMES_list=["John", "Mary","Scott","Curly","Moe","Jon Doe"]
NAMES_file.close()
NAMES_list=cPickle.load(NAMES.file)

anylistnames=(raw_input("Enter as many student names as you have"))

print ("\nReading the entire file into a list.")
for line in anylistnames:
print line


try:
name= int(raw_input("Enter a name"))
except:

def _init_(names):


any_listnames=(NAMES.readlines.sort())
any_listnames.writelines(NAMES.title())
NAMESfile=open("NAMES.txt","r")
all_the_data=NAMES.read()
NAMES.close()
textfile = open("NAMES.txt", "r")
all_the_data=anyNAMES.read()
NAMES.close()
lines = NAMES.readlines()
print lines
print len(lines)
for line in lines:
print line
NAMES.close()
print "Opening and closing the file."
anylistnames= open("names.txt", "r")
namesfile.close()
print "\nReading the entire file at once."
anylistnames_file = open("names.txt", "r")
whole_thing = names_file.read()
print whole_thing
namesfile.close()
for line in any_files:
print line
anylistnames.writelines(NAMES_file.title())
anyNAMESfile=open("names.txt","r")
all_the_data=any_namesfile.read()
anyNAMESfile.close()


try:
name= int(raw_input("Enter a name"))
exce[t(ValueError),e:
print "Data entered was not a name", e
else:
print "The value of name is", name

Um, I think you missed the part about code tags. You need to use them in order to preserve indentation! I can't be bothered to help until you've done that.

###Programmer Brian Austin
###FOP
###3/30/09
###Assignment 8
###Using a loop, allow the user to input as many student names as they like and store the names in a list. in title format
#then write the list of names to a file named NAMES.
#Read your file back into a list and sort the list.
#Write the sorted list to a different file named SORTEDNAMES.
#Read in and print (on the screen) all the names of the SORTEDNAMES file.
#Add logic to handle file I/O error exceptions.  You should include ALL I/O operations inside exception handling (open, read, write and close)



import cPickle
any_listnames=open("NAMES.TXT","w")
NAMES_list=["John", "Mary","Scott","Curly","Moe","Jon Doe"]
NAMES_file.close()
NAMES_list=cPickle.load(NAMES.file)



anylistnames=(raw_input("Enter as many student names as you have"))

print ("\nReading the entire file into a list.")
for line in anylistnames:
    print line
    

try:
    name= int(raw_input("Enter a name"))
except:
    
def _init_(names):
    

any_listnames=(NAMES.readlines.sort())
any_listnames.writelines(NAMES.title())
NAMESfile=open("NAMES.txt","r")
all_the_data=NAMES.read()
NAMES.close()
textfile = open("NAMES.txt", "r")
all_the_data=anyNAMES.read()
NAMES.close()
lines = NAMES.readlines()
print lines
print len(lines)
for line in lines:
    print line
NAMES.close()
print "Opening and closing the file."
anylistnames= open("names.txt", "r")
namesfile.close()
print "\nReading the entire file at once."
anylistnames_file = open("names.txt", "r")
whole_thing = names_file.read()
print whole_thing
namesfile.close()
for line in any_files:
    print line
anylistnames.writelines(NAMES_file.title())
anyNAMESfile=open("names.txt","r")
all_the_data=any_namesfile.read()
anyNAMESfile.close()


try:
    name= int(raw_input("Enter a name"))
    exce[t(ValueError),e:
         print "Data entered was not a name", e
         else:
         print "The value of name is", name

also I have another assignment..here it is..
here is the assignment directions:
Create a class named wpoMath. The class must contain the following:
1.) A constructor method that allows the calling program to specify a name for the object created, and then prints the object's name and a welcome message.
2.) Code "get" and "set" methods to retrieve and set the value of a property named "name" that reflects the object's name.
3.) Code a method named "plus" that adds a number to itself. It should respond with the answer in a property named "doubled."
4.) Code a method named "times" that multiples a number by itself. It should respond with the answer in a property named "squared".
5) Now, write the code that uses the wpoMath class to create an object. Then ask the user to supply a number. Use you object to print the object's name,the input number doubled, and the input number squared. I think I am missing the command to ask the user to supply a number ..but can you check for me?

#creating a Class
#

class wpoMath(object):
    """This is a Math object"""

#main program
wpoMath1=wpoMath()
wpoMath1.talk()
def _init_(self,wpoMath):
    print "I am wpoMath object"
    self.name = wpoMath
    print wpoMath1.wpoMath
def _str_(self):
    print "Hi, I'm, wpoMath, "\n"
    self._wpoMath=wpoMath
    def get_wpoMath(self):
        return self._wpoMath
def _init_(self, plus):
    self.plus = plus
def _str_(self):
    doubled = self.plus + 1
    return doubled
def _init_(self,times):
    selftimes = times
def _str_(self):
    squared = self.times * self.times
    return squared
wpoMath = WpoMath()
wpoMath.talk()
def _init(self.wpoMath):
    print self.name
    print doubled
    print squared

Why do you have this section:

try:
    name= int(raw_input("Enter a name"))
except:

The except junction needs an indented block after it for that respective action. Such as

try:
    name= int(raw_input("Enter a name"))
except:
    print 'There was an error'

And even then, I'm confused why you're trying to cast the raw_input for a name as an integer...

And also, shouldn't

NAMES_list=cPickle.load(NAMES.file)

be

NAMES_list=cPickle.load(NAMES_file)  #underscore, not period
#creating a Class
#

class wpoMath(object):
    """This is a Math object"""

#main program
wpoMath1=wpoMath()
wpoMath1.talk()
def _init_(self,wpoMath):
    print "I am wpoMath object"
    self.name = wpoMath
    print wpoMath1.wpoMath
def _str_(self):
    print "Hi, I'm, wpoMath, "\n"
    self._wpoMath=wpoMath
    def get_wpoMath(self):
        return self._wpoMath
def _init_(self, plus):
    self.plus = plus
def _str_(self):
    doubled = self.plus + 1
    return doubled
def _init_(self,times):
    selftimes = times
def _str_(self):
    squared = self.times * self.times
    return squared
wpoMath = WpoMath()
wpoMath.talk()
def _init(self.wpoMath):
    print self.name
    print doubled
    print squared

Sorry, but the above code doesn't make sense... why do you keep redefining _init_ and _str_ as different things??

Also, when you try to "overload" built in functions such as init, str, repr, etc. they should have TWO underscore ('_') characters... so _init_ should be __init__, _str_ should be __str__, etc...

Also take note that on your line 15 in the example above you have print "Hi, I'm, wpoMath, "\n" , which contains an extra double quote right before the \n... that's why you can see the blue color extending all the way to the end of your code... It thinks you started a new string.

Fix your errors and re-post your code along with what you're stuck on after fixing those mistakes and we can help further.

One last thing, avoid using wpoMath and WpoMath as variables, class names interchangeably... It's best practice to do something like this:

class wpoMath(object):
     def __init__(self):
         # Something

my_object = wpoMath()

Basically, name it something completely different instead of just changing the case of a letter or two... for your own sanity's sake.... but that's just my opinion I guess.

###Programmer Brian Austin
###FOP
###3/30/09
###Assignment 8
###Using a loop, allow the user to input as many student names as they like and store the names in a list. in title format
#then write the list of names to a file named NAMES.
#Read your file back into a list and sort the list.
#Write the sorted list to a different file named SORTEDNAMES.
#Read in and print (on the screen) all the names of the SORTEDNAMES file.
#Add logic to handle file I/O error exceptions.  You should include ALL I/O operations inside exception handling (open, read, write and close)



import cPickle
any_listnames=open("NAMES.TXT","w")
NAMES_list=["John", "Mary","Scott","Curly","Moe","Jon Doe"]
NAMES_file.close()
NAMES_list=cPickle.load(NAMES.file)



anylistnames=(raw_input("Enter as many student names as you have"))

print ("\nReading the entire file into a list.")
for line in anylistnames:
    print line
    

try:
    name= int(raw_input("Enter a name"))
except:
    
def _init_(names):
    

any_listnames=(NAMES.readlines.sort())
any_listnames.writelines(NAMES.title())
NAMESfile=open("NAMES.txt","r")
all_the_data=NAMES.read()
NAMES.close()
textfile = open("NAMES.txt", "r")
all_the_data=anyNAMES.read()
NAMES.close()
lines = NAMES.readlines()
print lines
print len(lines)
for line in lines:
    print line
NAMES.close()
print "Opening and closing the file."
anylistnames= open("names.txt", "r")
namesfile.close()
print "\nReading the entire file at once."
anylistnames_file = open("names.txt", "r")
whole_thing = names_file.read()
print whole_thing
namesfile.close()
for line in any_files:
    print line
anylistnames.writelines(NAMES_file.title())
anyNAMESfile=open("names.txt","r")
all_the_data=any_namesfile.read()
anyNAMESfile.close()


try:
    name= int(raw_input("Enter a name"))
    exce[t(ValueError),e:
         print "Data entered was not a name", e
         else:
         print "The value of name is", name

If I were you I'd learn how to use something like tabNanny to check your syntax.

Your indentation is all off and you've got random code in random places that doesn't really make sense.... I suggest you start small like woooee said and work your way up from there. Do you know how to create a while loop?

Here's the Python documentation on compound statements (if, for, while, etc.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.