Skip to content
Advertisement

Printing pair of numbers using for loop – Python

I am a beginner in python and I need some help with a case: I need to print pairs of numbers which are input from a for loop – for example

JavaScript

Let’s say we enter 3 2 1 4 5 0 4, I need to print the sum of the paired numbers – 3 + 2, 1 + 4 etc. Could anybody brighten me up with an idea on how exactly this is done?

Advertisement

Answer

I tried to keep much of your code:

JavaScript

I made a few changes:

  1. since the loop requests 2 inputs instead of one, the loop only runs up to count_of_numbers. I could have used “+ 1”, but preferred to start at zero, as the variable i (formerly numbers) isn’t used.
  2. In order to guide the user running this program, I’ve added some text to the input() calls
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement