print
function accepts an end
keyword argument to specifies the end of the string after printing. By default it's set to new line (\n
), you can simply use a space. Also note that checking the truths value of any expression with == True
is wrong since True
interprets as 1 and every thing that returns 1 will be interpreted as True. You can simply use if w.isupper()
:
def WhichAreCaps(Word):
for w in Word:
if w.isupper():
print(w, end=' ')
Another way is yield
ing the vowels in your function and make it a generator:
def WhichAreCaps(Word):
for w in Word:
if w.isupper():
yield w
Then you can join the result in any way you like and print it:
print(','.join(WhichAreCaps(Word)))
After all, as a more pythonic approach for this ask you can simply use a list comprehension within str.join
:
print(' '.join([w for w in Word if w.isupper()]))