Write a program with python that reads four integers and prints two pairs if the input consists of two matching pairs in some order and not two pairs otherwise For example 1 2 2 1 two pairs 1
Here's one way to write the program in Python:
a, b, c, d = input().split() # read four integers as a single line of input and split them into separate variables
if (a == b and c == d) or (a == c and b == d) or (a == d and b == c):
print("two pairs")
else:
print("not two pairs")
The program reads four integers as a single line of input, separated by spaces. It then splits the input into separate variables a, b, c, and d.
The if statement checks whether any two pairs of variables are equal. It does this by using the and and or operators to combine several equality tests. If any of these tests is true, the program prints "two pairs". Otherwise, it prints "not two pairs".
原文地址: https://www.cveoy.top/t/topic/boWk 著作权归作者所有。请勿转载和采集!