ΣνΜDr. Sharon's Math PlatformSyvara Learning
Question Bank › 📘 Undergraduate › Programming for Engineers › Q9

Q9 · Write a Python for loop that computes the sum of every integer from 1 to n.

Loops and Control Flow 🟢 Intro Coding
Question

Write a Python for loop that computes the sum of every integer from 1 to n.

(a) Use the accumulator pattern. Verify: n=3 gives 6, n=10 gives 55.
(b) Write the same in one line using sum() and range().
(c) Iterate over the string "ENSC" and print each character on its own line.

🔒

Log in to see the worked solution

Enter your email to get started. Your first free solutions in every course unlock as soon as you verify.

Log in or sign up with email
← Previous Next →
Working…