Python Forum
function help (totaly beginner)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function help (totaly beginner)
#14
(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()
Reply


Messages In This Thread
function help (totaly beginner) - by thanikos - Dec-07-2017, 12:32 PM
RE: function help (totaly beginner) - by thanikos - Dec-07-2017, 12:44 PM
RE: function help (totaly beginner) - by wavic - Dec-07-2017, 12:50 PM
RE: function help (totaly beginner) - by thanikos - Dec-07-2017, 12:56 PM
RE: function help (totaly beginner) - by wavic - Dec-07-2017, 01:10 PM
RE: function help (totaly beginner) - by gruntfutuk - Dec-07-2017, 03:07 PM
RE: function help (totaly beginner) - by thanikos - Dec-10-2017, 11:25 PM
RE: function help (totaly beginner) - by wavic - Dec-11-2017, 02:02 AM
RE: function help (totaly beginner) - by thanikos - Dec-11-2017, 08:55 AM
RE: function help (totaly beginner) - by Item97 - Dec-11-2017, 08:57 AM
RE: function help (totaly beginner) - by wavic - Dec-11-2017, 09:54 PM
RE: function help (totaly beginner) - by thanikos - Dec-12-2017, 07:12 PM
RE: function help (totaly beginner) - by wavic - Dec-12-2017, 08:48 PM
RE: function help (totaly beginner) - by thanikos - Dec-13-2017, 08:32 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020