masterofpuppets 19

[QUOTE=Yeen;1049382]output.txt was created, but it was identical to words.txt.

My attempts so far in using re.sub have been... fruitless :icon_eek:[/QUOTE]

hi,
you could do something like this:

[CODE]f = open( "test.txt", "r" )
text = f.read()
f.close()

newText = ""
for each in text:
if each == ".":
each = "" #Or replace it with whatever you like.
newText += each

f = open( "output.txt", "w" )
f.write( newText )
f.close()[/CODE]

hope this helps :)

masterofpuppets 19

hi,
here's an example class to represent students :)

[CODE]import datetime

class Student:
def init( self, firstname, lastname, birthdate, matricNum, gender ):
self.firstname = firstname
self.lastname = lastname
self.birthdate = birthdate
self.matriculationNum = matricNum
self.gender = gender

def getFirstName( self ):
    return self.firstname
def getLastName( self ):
    return self.lastname
def getBirthdate( self ):
    return self.birthdate
def getMatricNum( self ):
    return self.matriculationNum
def getGender( self ):
    return gender

def displayStudent( self ):
    return self.matriculationNum + " " + self.lastname + " " + self.firstname

def getDate( self ):
    return datetime.datetime.today().strftime( "%d" ), datetime.datetime.today().strftime( "%m" ), datetime.datetime.today().strftime( "%Y" )

def age( self ):
    day, month, year = self.getDate()
    stDay, stMon, stYear = self.birthdate.split( "/" )[ 0 ], self.birthdate.split( "/" )[ 1 ], self.birthdate.split( "/" )[ 2 ]
    ageInYears = int( year ) - int( stYear )

    if int( month ) < int( stMon ) or ( int( month ) == int( stMon ) and int( day ) < int( stDay ) ):
        ageInYears -= 1
    return ageInYears

def emailAddress( self ):
    return self.matriculationNum + "@university.uk"

student1 = Student( "John", "Smith", "07/10/1989", "123456", "male" )
student2 = Student( "Matthew", "Jones", "13/11/1986", "987654", "male" )

print student1.displayStudent()
print student1.getBirthdate()
print student1.age()
print student1.emailAddress()
print
print student2.displayStudent()
print student2.getBirthdate()
print student2.age()
print student2.emailAddress()[/CODE]

it's just to illustrate some of the main points...
The init method is the constructor for the class, so here you can put all the relevant variables that you're going to use in the whole class and you can access these variable ...

masterofpuppets 19

hi :)
for the first problem you could do something like this:

[CODE]public class Mymath {

public calculateFactor( int a, int b ) {
    if ( a < b && b % a == 0 )
        return true;
    elif ( a > b && a % b == 0 )
        return true;
    else
        return false;
}

}[/CODE]

and for the second part see if this is any helpful :):

[CODE]import java.util.Scanner;

public class Test {

public static void main( String[] args ) {
    Scanner in = new Scanner( System.in );
    String goOn = "y";
    int n, largest = 0;
    do {
        System.out.println( "Input an integer number:" );
        n = in.nextInt();

        for ( int i = 1; i < n; i++ )
            if ( n % i == 0 )
                if ( i > largest )
                    largest = i;
        System.out.println( "Largest divisor: " + largest );
        System.out.println( "Another input (y/n)?" );
        goOn = in.nextLine();
        goOn = in.nextLine(); //doesn't work in there's only one don't know why.
        largest = 0;

    } while ( goOn.equals( "y" ) );
  }

}[/CODE]