+ 2
Loop program
Can anyone write a code in for loop using python - 1 2 3 4 5 6 In a simple way with explanation?
16 Respostas
+ 4
Ok.. I dont understand something about your code... anyway try to understand next code:
# row first number
k = 1
# Do for 4 rows
# x is the number current row
for x in range(1,4+1):
# y will be any number of rows
# We want start from k up to
# k + x because any row
# will contains numbers count
# equals the row number (the
# row 1 contains 1 number,
# the row 2 contains 2 numbers
# etc...)
for y in range(k, k+x):
# print every number
print(y,end=" ")
# at end of row update the next
# first number
k = k+x
print()
+ 4
Well, and that you understand is important đđ»
+ 2
I would see first you attempt and start from it...
+ 1
I tried already, should I show?
+ 1
Yes...Post the attempt.... The code that you tried...
+ 1
Thank you,I got it
+ 1
ch = 0 # number of character printed
row = 1 # row counter
for i in range(1, 100): # increase the ending value if you want to print more rows
print(i, end=' ')
ch += 1
if ch == row:
print()
ch = 0
row += 1 # if printed character is the same as row, print a new line and increase the row by 1 for the next iteration
if row == 4: # end the loop before it goes to print row 4 (or any number you specific)
break
+ 1
We use Python code with two nested loops:
1. The outer loop counts the rows (1st row, 2nd row, 3rd row).
2. The inner loop prints the numbers within each row.
The code starts with the number 1 and uses the outer loop to count rows from 1 to 3. In each row, the inner loop prints the current number and increments it. The pattern is created, and each row has the right numbers!
The Python code looks like this:
-----------------------------------------------------
PY code:
num_rows = 3
current_number = 1
for i in range(1, num_rows + 1):
for j in range(i):
print(current_number, end=" ")
current_number += 1
print()
-----------------------------------------------------
Run this code, and you'll get the pattern! It's a fun and simple way to create patterns using loops in Python.
0
That's the attempt of mine
0
{"advice": "LOCK_BOOTLOADER,RESTORE_TO_FACTORY_ROM"}
0
with
0
adb shell sh /storage/emulated/0/Android/data/moe.shizuku.privileged.api/start.sh
0
Are you understand?
0
with
0
without