Python Forum
function help (totaly beginner)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function help (totaly beginner)
#15
The for loop in stars function could look like this:
I have changed the names of the variables so now if you look at it, you know what is going on. Single letter var names don't speak too much for themselves.
You don't need the index to get each value of an iterable.

def stars(word):
    for char in word : # on every iteration char holds the next letter of the word
        print("*", char, sep='', end='')
    print("*")
The "encryption"...
Do you care if each letter is lower or uppercase? If you do, then you need all letters. Then you need two lists.

The programming is not as complicated as the most people think it is. It could and it is. Very. But when it comes to what you are studying right now, all it's needed is to imagine, how would you do it by hand. And implement it in a code.

So you take a letter of the word and you get the index of that letter in the list and move it to the right - add 1 to the index. Check if the letter is the last one and take the first one if that is the case. Otherwise, you get an error: List index out of range.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
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