Q:

Why will this not output the diceroll2 function?

I'm making a turn-based dice game for my Computer Science GCSEs and cannot understand why a certain part of my program will not run, or at least output.
class player1:
    def __init__(self):
        self.rolls = 5
class player2:
    def __init__(self):
        self.rolls = 5

def dicerollp1():
    print("foo")

def dicerollp2():
    print("2foo")

while player1.rolls > 0 and player2.rolls > 0:
    dicerollp1()
    player1.rolls += -1
if player1.rolls > player2.rolls:
    dicerollp2()
    player2.rolls += -1

Shouldn't 2foo be outputted instead of nothing?

A:

You are trying to use the class name to call a class instance method player1.rolls() , instead of that, what you should be doing is to use an object of the class to do that. 

p1 = player1()
p1.rolls()

One class player is enough for your code, you don't need two identical classes, and call two instances on it (Thanks @khelwood)
dicerollp1 and dicerollp2 can be moved inside the class, perhaps by adding an additional attribute player_number
You can perhaps change player1.rolls += -1 to player1.rolls -= 1
So the refactored code will look like

#One player class
class player:
    #Player number as attribute to diceroll
    def __init__(self, player_number):
        self.rolls = 5
        self.player_number = player_number

    #One diceroll function
    def diceroll(self):
        print("foo{}".format(self.player_number))

#Instantiate object of class player
p1 = player(1)
p2 = player(2)

#Use them in the logic
while p1.rolls > 0 and p2.rolls > 0:
    #Refer to p1's diceroll
    p1.diceroll()
    p1.rolls += -1
if p1.rolls > p2.rolls:
    # Refer to p2's diceroll
    p2.diceroll()
    p2.rolls += -1

Also after your while loop, p1.rolls=0 and p2.rolls=5, and hence p1.rolls > p2.rolls will be false and the if will not be executed, hence the output will be
foo1
foo1
foo1
foo1
foo1

