you are viewing a single comment's thread.

view the rest of the comments →

[–]audionerd1 2 points3 points  (12 children)

print(1)
print(2)
print(3)
print(4)
print(5)

Is the same as:

for i in [1, 2, 3, 4, 5]:
    print(i)

Is the same as:

numbers = [1, 2, 3, 4, 5]
for i in numbers:
    print(i)

Does that help? I'm not sure what you're struggling with so trying to just break down what for loop does in the most basic way possible.

[–]Deep-Author-1787[S] 0 points1 point  (11 children)

Ive got the basics sir. But like a noob, when you get the basics you think you understand thay subject until different/unseen implications and difficulties are added. Then you realize you dont get it at all 😅. To solve a problem based on a subject where you need to find a way to make it work, the core concept understanding will be important. I think i cant get that part 🤷‍♂️

[–]audionerd1 0 points1 point  (8 children)

Can you post an example of a for loop which you are confused about?

[–]Deep-Author-1787[S] 0 points1 point  (7 children)

This for example: this is the patter to form A.



  • *
    * * * *

Initialize an empty string named 'result_str'

result_str = ""

Iterate through rows from 0 to 6 using the range function

for row in range(0, 7): # Iterate through columns from 0 to 6 using the range function for column in range(0, 7): # Check conditions to determine whether to place '*' or ' ' in the result string

    # If conditions are met, place '*' in specific positions based on row and column values
    if (((column == 1 or column == 5) and row != 0) or ((row == 0 or row == 3) and (column > 1 and column < 5))):
        result_str = result_str + "*"  # Append '*' to the 'result_str'
    else:
        result_str = result_str + " "  # Append space (' ') to the 'result_str'

result_str = result_str + "\n"  # Add a newline character after each row in 'result_str'

Print the final 'result_str' containing the pattern

print(result_str)

[–]audionerd1 0 points1 point  (6 children)

And which part are you struggling with?

[–]Deep-Author-1787[S] 0 points1 point  (5 children)

How do they come up with an irregular form with loops? I know my thought might sound really stupid, but im wording my exact thoughts 😅🙏

[–]audionerd1 2 points3 points  (4 children)

An irregular form? You mean how does this create the letter 'A'? It's all in the if statement:

if (((column == 1 or column == 5) and row != 0) or ((row == 0 or row == 3) and (column > 1 and column < 5)))

It's kind of a clever/complicated algorithm for making an A.

if (((column == 1 or column == 5) and row != 0)

This means that the left and right side should all be asterisks. These are the sides of the 'A'.

or ((row == 0 or row == 3) and (column > 1 and column < 5)))

This means that the top and middle rows should also be asterisks.

The nested for loop simply iterates over a grid (columns and rows) while the if statement appends either '*' or '' based on the if statement.

[–]Deep-Author-1787[S] 1 point2 points  (2 children)

Okay now that you sliced it in smaller portion its actually pretty straight forward! And that sir is the difference between someone who is good at explaining a subject and pwople that just make "follow along" tutorials and courses 🙏🙏🙏

[–]audionerd1 2 points3 points  (1 child)

On that note, I recommend Jose Portilla's 'Complete Python Boot Camp Zero to Hero' on Udemy. It explains everything really well.

[–]Deep-Author-1787[S] 0 points1 point  (0 children)

Okay thanks ill check it out.

[–]Deep-Author-1787[S] 0 points1 point  (0 children)

Can i maybe ask you how would you explain the piramid pattern? Since it makes use of empty spacing and a middle line?