-1

I am trying to write as the question is stated, Write a program that accepts a positive integer from the user and print the first four multiples of that integer; Use while loop (Python)

total = 0

number = int(input("Enter integer: "))
while number <= 15:
     total = total + number 
print(number)

SAMPLE

Enter integer: 5
0
5
10
15

this is the example my professor wanted

This is what i have so far, but i'm a bit lost...

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 6
    ["Can Someone Help Me?" is not a valid SO question](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question). This usually suggests that what you need is time with a local tutor or walk through a tutorial, rather than Stack Overflow. Best of all, each tutorial will teach you a collection of related techniques, rather than merely solving the immediate problem. "I'm a bit lost" is not a specific problem -- not for Stack Overflow. – Prune Aug 28 '19 at 15:36

4 Answers4

0

You should loop over a counter variable instead of a hard coded limit

counter = 1
while counter <= 4:
    counter += 1
    total = total + number 
    print(number)
Sayse
  • 42,633
  • 14
  • 77
  • 146
0

The loop condition should be set on total, not number, and total should be incremented by 1, not number (assuming total is used as a loop counter):

total = 0
number = int(input("Enter integer: "))
while total <= 3:
     print(total * number)
     total = total + 1

Sample:

Enter integer: 5
0
5
10
15
DjaouadNM
  • 22,013
  • 4
  • 33
  • 55
0

A normal while loop that counts upto 4:

count, total = 0, 0

number = int(input("Enter integer: "))
while count < 4:
     print(total)
     total = total + number     
     count += 1

Python for loop is more pythonic than while:

number = int(input("Enter integer: "))

for i in range(4):
    print(number * i)
Austin
  • 25,759
  • 4
  • 25
  • 48
0

Although you have the right idea from the example there's still a couple of things the sample is missing. 1. You don't check whether the input is positive or not 2. The while loop is dependent on knowing the input

Try the following:

# Get Input and check if it's positive
number = int(input('Enter positive integer: '))
if number <= 0:
    number = int(input('Not positive integer, enter positive integer: '))

# This increments i by one each time it goes through it, until it reaches 5
i=1
while i < 5:
    new_number = number*i
    i = i + 1
    print(new_number)

Note: This does not take into account if the input is a letter or string. If so, it'll throw an error.

EAA
  • 87
  • 1
  • 9