n = int (input("1))
result = 0
i = 1
while i < n + 1:
result = result + i
print(i, end = "")
if i < n:
print("+", end = "")
else:
print("=", result, end = "")
i = i + 1
n = int (input(("2) fixed power"))
result = 0
i = 0
while i < n:
i = i + 1
result = result + i
print(i, end = "")
if i < n:
print("+", end = "")
else:
print("=", result, end = "")
n = int (input("3rd fixed power"))
result = 0
for i in range(1, n + 1, 1):
result = result + i
print(i, end = "")
if i < n:
print("+", end = "")
else:
print("=", result, end = "")
I heard the difference between these three phrases when I was studying, but I couldn't understand them well
Is there anyone who can teach me?
python
I was free, so I typed the contents of the screenshot in code. Please press the green button on the upper right, "Waiting for approval," and approve the correction.
Answer: Cut to the core. Only the expression of the repeat statement is different.
n = int (input("1))
i = 1
while i < n + 1:
# What to repeat
i = i + 1
n = int (input(("2) fixed power"))
i = 0
while i < n:
i = i + 1
# What to repeat
n = int (input("3rd fixed power"))
for i in range(1, n + 1, 1):
# What to repeat
© 2024 OneMinuteCode. All rights reserved.