(Dec-11-2017, 09:54 PM)wavic Wrote: (Dec-07-2017, 01:10 PM)wavic Wrote: create a variable which will contain the final result and put a '*' in it during the initialization. On each iteration add a letter to it followed by a '*'. and you get the final result as requested. All this inside the function.
def all_stars(s):
# create a variable which will contain the final result and put a '*' in it.
result = "*"
# the for loop. A pseudo code. I wont write it for you.
for each character in s:
add the character to 'result'
add a '*' right behind the character
return the result.
You have to consider that the strings are immutable type of data so adding something to a string is meaning to assign a new value to it:
my_string = 'hello'
my_string = my_string + ', world'
Thanks! I gott it. The first function works and prints the stars.
Now i must add a new funktion that "encrypts" the input word, somehing like this: ABCD gets BCDE...moving the letters of the word by one.
I thougt i make an array with the alfabet first...but i'm stuck of course! This is the code so far:
alfabet = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
def stars(s):
for i in range(len(s)):
print("*",s[i],sep='',end='')
print("*")
def krypt():
for i in(alfabet):
print()
text = input("write a word ")
stars(text)
krypt()
print()