One variable for 4 numbers



  • Pitton. If the numbers are negative? Only one variable (a) should be used to solve the assignment. The numbers are all four. And then to answer: truth or lie. The mass and other cycles cannot be used (except if)



  • [news]

    once the author added an additional condition:

    The mass and other cycles cannot be used (except if)

    res = int(input('Введите число #1: ')) > 0
    res &= int(input('Введите число #2: ')) > 0
    res &= int(input('Введите число #3: ')) > 0
    res &= int(input('Введите число #4: ')) > 0
    print('ПРАВДА' if res else 'ЛОЖЬ')
    

    But it's in a clear way. if not used :

    [GROANS]

    May be:

    data = list(map(int, input('Введите числа через пробел: ').split()))
    

    print('Все числа положительные' if all(i > 0 for i in data) else 'Не все числа положительные')

    The truth is, in the task, there's a four-piece entry information, so you can:

    data = []
    for i in range(4):
    data.append(int(input(f'Введите число №{i}')))

    print('Все числа положительные' if all(i > 0 for i in data) else 'Не все числа положительные')


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2