mardi 15 novembre 2016

Using multiple conditions in an if statement [on hold]

I am trying to create a program that follows 2 rules:

  • The total value of the numbers in the list must be a multiple of 3
  • No number must be one less than the previous number, even if the pattern is repeated indefinitely

For example, the following sequence is valid:

5 2 2

But the following, is not:

6 5 1 (5 is one less than the previous number, so this does not follow rule 2)

My attempt so far:

num1, num2, num3 = input('Number 1: '), input('Number 2: '), input('Number 3: ')
total = num1 + num2 + num3
if not total % 3 == 0 and num1 == num2 + 1 and num2 == num3 + 1 and num3 == num1 + 1:
    print 'No.'

However, there seems to be a syntax error between the space, here:

and num3

Aucun commentaire:

Enregistrer un commentaire