mercredi 13 juillet 2016

How to complete this function then print it out, using Python?

I'm having a hard time to understand how to work with functions - I can make then but after that I don't know how to use them. My question is how can I print this code with a function?

string = "Hello"
reverse = string[::-1]
print(reverse)

I tried putting it in a function but I cannot make it print Hello.

def reverse_a_string(string):
    string = "Hello"
    reverse = string[::-1]
    print(reverse)

also tried this

def reverse_a_string(string):
    string = "Hello"
    reverse = string[::-1]

print(reverse)

Nothing seems to work. I'm having same problem with this as well.

total = 0

def length(words):

    for i in words:
        total += 1
    return total

Aucun commentaire:

Enregistrer un commentaire