It is currently 19 Jan 2021, 09:10
| ||||
| ||||
|
|
Input and For loops Exercise

- tim
- View:
|Posts
- Topic Posts: 4/7 | Posts: 5209
- Joined: 26 Sep 2016, 00:16
- Cash on hand: 75,172.37 GLP
- Bank: 205,555,073.00 GLP
- Gender: Guy
- Location: Canada
- GIMP Version: 2.10.X
- Paint Blotches blog
- Play them songs blog
- Personal Blog
- x 3064
- x 1010
- Contact:
Input and For loops Exercise
Write a program that
1. Prompts the user for input of a string
2. Uses for loop to loop through each character of string and inserting each character to the beginning of a list which starts out as empty list (Note: a string can be viewed as a list of characters/letters).
3. Uses for loop to loop through each character of the inserted list and prints out each character/letter so that the input string from step 1. is now print out in reverse. (Note: to print multiple print statements without newline character between them, just pass in a 2nd named parameter of
Solution:
1. Prompts the user for input of a string
2. Uses for loop to loop through each character of string and inserting each character to the beginning of a list which starts out as empty list (Note: a string can be viewed as a list of characters/letters).
3. Uses for loop to loop through each character of the inserted list and prints out each character/letter so that the input string from step 1. is now print out in reverse. (Note: to print multiple print statements without newline character between them, just pass in a 2nd named parameter of
end=""
which tells it to not end a line with newline character).Solution:
Spoiler:
aka Tin
Tim,
I could not use For Loop.
I had trouble understanding what the problem was asking for.
Besides understanding the logic of the exercise, I also had to understand the text written in English.
I thought I would at some point apply the and add the characters in the empty list.
But I didn't know how to get the characters individually from the string provided by the user.
And with the example of the For Loops lesson, I was not able to apply this to a list.
For item in Mylist []: ??
Looking for For Loops, I found an example of how to use While loop, and I ended up understanding this function better.
Temporarily resolved (I think) using While.
Tim, thanks for the fun !! 
I could not use For Loop.

I had trouble understanding what the problem was asking for.
Besides understanding the logic of the exercise, I also had to understand the text written in English.

I thought I would at some point apply the
Code: Select all
mylist.insert (index, item)
But I didn't know how to get the characters individually from the string provided by the user.

And with the example of the For Loops lesson, I was not able to apply this to a list.
For item in Mylist []: ??
Looking for For Loops, I found an example of how to use While loop, and I ended up understanding this function better.
Temporarily resolved (I think) using While.
But I still will not check the answer. I will continue trying to understand the For Loop, and then try again to solve this exercise.
For now this is my solution:Spoiler:

"I feel that in both art and music, it's not the success that matters but the pleasure it gives you. Focus on the pleasure and the learning will come naturally." - Brian Weston
- tim
- View:
|Posts
- Topic Posts: 4/7 | Posts: 5209
- Joined: 26 Sep 2016, 00:16
- Cash on hand: 75,172.37 GLP
- Bank: 205,555,073.00 GLP
- Gender: Guy
- Location: Canada
- GIMP Version: 2.10.X
- Paint Blotches blog
- Play them songs blog
- Personal Blog
- x 3064
- x 1010
- Contact:
As long as you're able to come up with solution then I guess you've learned something.
While loops are fine as an alternative.
While loops are fine as an alternative.
aka Tin
If the question is simply to reach the final result ... yes, I learned a lot from this challenge.
But if the question is didactic, the ends do not justify the means.
I wasn't understanding the For Loops, and I think the exercise above all else is to better explore lesson theory.
I managed to come up with a result. I do not know if that is what was really requested.
It's time to see the Spoiler and find out the easiest way to do it!
Spoiler:
"I feel that in both art and music, it's not the success that matters but the pleasure it gives you. Focus on the pleasure and the learning will come naturally." - Brian Weston
- tim
- View:
|Posts
- Topic Posts: 4/7 | Posts: 5209
- Joined: 26 Sep 2016, 00:16
- Cash on hand: 75,172.37 GLP
- Bank: 205,555,073.00 GLP
- Gender: Guy
- Location: Canada
- GIMP Version: 2.10.X
- Paint Blotches blog
- Play them songs blog
- Personal Blog
- x 3064
- x 1010
- Contact:
I wasn't able to reverse the initial string order, using For Loop.

As can be seen in the code below, the final inversion showed flaws.
Spoiler:
Then by chance, I discovered the .reverse (), and threw in the towel.

Then, when I checked the answer, I understood that the Index should be fixed at position 0 (zero), and that with the new entries, it would be pushed to the right.
Even though I failed the challenge using For Loops, I learned a lot on the way.
"I feel that in both art and music, it's not the success that matters but the pleasure it gives you. Focus on the pleasure and the learning will come naturally." - Brian Weston
- tim
- View:
|Posts
- Topic Posts: 4/7 | Posts: 5209
- Joined: 26 Sep 2016, 00:16
- Cash on hand: 75,172.37 GLP
- Bank: 205,555,073.00 GLP
- Gender: Guy
- Location: Canada
- GIMP Version: 2.10.X
- Paint Blotches blog
- Play them songs blog
- Personal Blog
- x 3064
- x 1010
- Contact:
| ||||
| ||||
|
-
- Similar Topics
- Replies
- Views
- Last post
-
- 17 Replies
- 6824 Views
-
Last post by Pat625
06 Nov 2020, 07:02
-
- 5 Replies
- 3437 Views
-
Last post by tim
10 Apr 2020, 01:31
-
-
Set Render/Pattern/Sinus Permanently to FG and BG Colors
by Lenny » 17 Apr 2020, 06:12 » in GIMP Script Requests - 4 Replies
- 3523 Views
-
Last post by Lenny
20 Apr 2020, 20:04
-
-
- 4 Replies
- 2938 Views
-
Last post by tim
05 Jul 2020, 03:51
-
- 5 Replies
- 3188 Views
-
Last post by neurolurker
25 Jul 2020, 05:17
-
- 0 Replies
- 824 Views
-
Last post by cowherd
29 Sep 2020, 03:29
-
-
Transparent to color and content to transparent plug-in
by tim » 01 Oct 2020, 13:24 » in GIMP Python Fu Scripts/Plug-ins - 1 Replies
- 897 Views
-
Last post by GJL
01 Oct 2020, 14:04
-
Who is online
Users browsing this forum: No registered users and 1 guest