Trying to learn some python and I have the following task:
- Get a phrase from the user as an input.
- Check if the input contains a consonant from a consonants tuple\list that I declare in the code.
- For every consonant in the user input, print the consonant followed by the letter 'o' and the consonant itself.
For example:
- User types the word 'something' as an input
- Output should be: 'sosomometothohinongog' (vowels do not exist in the consonant tuple and hence are not being appended).
This is my code:
#!/usr/bin/python
consonant = ('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z')
def isConsonant(user):
for consonant in user:
print consonant + "o" + consonant
var = raw_input("type smth: ")
isConsonant(var)
Here is what I get:
root@kali:~/py_chal# ./5.py
type smth: test
tot
eoe
sos
tot
I have trouble with:
- The code treats vowels as consonants even though they are not in the list (notice the 'e').
- the 'print' method adds a new line - This was solved by importing the sys module and using 'write'.
Any tips are greatly appreciated.
in. It means different things in aforloop vs. anifstatement.