Dec-07-2017, 03:07 PM
(This post was last modified: Dec-07-2017, 03:08 PM by gruntfutuk.)
At least you've made a start and put some structure in place.
Before the loop starts, create a variable pointing to an empty string, e.g.
def stars(s): letters = len(s) n = letters-1 for i in range(letters):You don't need to check the length of a string in Python for this because you can do a loop using
for character in s:
and each time the loop goes round, the variable character (in my example) will hold a copy of each successive character in the source string s. (Note that generally we avoid single letter variable names as they are not very informative.)Before the loop starts, create a variable pointing to an empty string, e.g.
starword = ""
, and then each time through the loop you can add the character and a star. When you have finished, you can return the final new string with the return statement: return starword
.def main(): word = input("write a word ") print(word)Ok, so this gets some input and prints it out. You need to add a call to your function before the print out to give a new version of word in it with the stars that you want added. You could do
word = stars(word)
.
I am trying to help you, really, even if it doesn't always seem that way