jeudi 27 octobre 2016

Python: How to print results from conditions all in one line

I'm new to coding, and I found this exercise problem in a Python practice website. The instructions go like this:

"Write a function translate() that will translate a text into "rövarspråket" (Swedish for "robber's language"). That is, double every consonant and place an occurrence of "o" in between. For example, translate("this is fun") should return the string "tothohisos isos fofunon".

So I inputted this code:

def translate(string): vowels=['a','e','i','o','u'] for letter in string: if letter in vowels: print(letter) else: print(letter+'o'+letter) print(translate('this is fun'))

and I got this:

tot hoh i sos o i sos o fof u non None

So how do I put all these strings in one line? I've been scratching my head for so long. Please help and thank you:)

Aucun commentaire:

Enregistrer un commentaire