Calculating chmod based on user input This program asks the user for input three times, and based on that input, calculates the chmod. I have included comments with questions and clarifications in the code.

I would like to have these questions answered and help with making the if ... in ... part shorter, if that's possible.

'''
This program asks the user for input three times, and based on that input, calculates the chmod.
'''

'''
This is a simple function that prevents me from repeating myself.
Usage:
    whoCan('execute')
will return 'Who can execute?'
'''

def whoCan(doThis):
    '''
    If I use `print` instead of `return` here, this is the output:

     Who can read?
     None

    Why is that?
    '''
    return "Who can %s?" % doThis

'''
Ask the user for input in the form of 'ow', 'gr' and 'ot'.
FYI:
    ow = owner
    gr = group
    ot = other

chmod 777 would be  owgrot
                    owgrot
                    owgrot
'''

read = raw_input(whoCan('read'))
write = raw_input(whoCan('write'))
execute = raw_input(whoCan('execute'))

'''
I didn't have any success with
    readValue, writeValue, executeValue = int()
Why?
'''

readValue = 0
writeValue = 0
executeValue = 0

# There must be a shorter way to write this...

if 'ow' in read:
    readValue += 4
if 'gr' in read:
    readValue += 2
if 'ot' in read:
    readValue += 1

if 'ow' in write:
    writeValue += 4
if 'gr' in write:
    writeValue += 2
if 'ot' in write:
    writeValue += 1

if 'ow' in execute:
    executeValue += 4
if 'gr' in execute:
    executeValue += 2
if 'ot' in execute:
    executeValue += 1

# And print the chmod

print readValue, writeValue, executeValue
Concise coding

After moving the documentation of the function after the line containing def as the convention stands we have:

def whoCan(doThis):
    '''
    This is a simple function that prevents me from repeating myself.
    Usage:
        whoCan('execute')
    will return 'Who can execute?'

    If I use `print` instead of `return` here, this is the output:

     Who can read?
     None

    Why is that?
    '''
    return "Who can %s?" % doThis


The second paragraph is just a doubt that is not really relevant to this function (the reason is that: using print creates a function with no return of which the return is implicitly None, that is printed by raw_input), so we can remove it:

def whoCan(doThis):
    '''
    This is a simple function that prevents me from repeating myself.
    Usage:
        whoCan('execute')
    will return 'Who can execute?'
    '''
    return "Who can %s?" % doThis


I can already see that it is a (simple) function, and functions are usually used to avoid repetition so we can remove it too:

def whoCan(doThis):
    '''
    Usage:
        whoCan('execute')
    will return 'Who can execute?'
    '''
    return "Who can %s?" % doThis


In fact we may remove this whole function as it is just doing "Who can {}?".format(action) where x is the input.

To avoid repetition we will use a generator expression:

read, write, execute = (raw_input("Who can {}?".format(action)) for action in ('read', 'write', 'execute'))


The last part can be shortened with a dictionary and a function that calls sum on a generator expression:

name_to_val = {'ow' : 4, 'gr' : 2, 'ot' : 1}

def chmod_value(x):
    return sum(name_to_val(name) for name in name_to_val.keys() if name in x)


You also do not need to initialize variables with zero, in fact you do not need variables at all:

print [chmod_value(x) for x in (read, write, execute)]