Q. Given a list A of numbers, you have to print those numbers which are not multiples of 3.
Input Format:
The first line contains the numbers of list A separated by a space.
Output Format:
Print the numbers in a single line separated by a space which are not multiples of 3.
Example:
Input:
1 2 3 4 5 6 5
Output:
1 2 4 5 5
Explanation:
Here the elements of A are 1, 2, 3, 4, 5, 6, 5 and since 3, 6 are the multiples of 3 hence after removing them the list becomes 1, 2, 4, 5, 5
Solution:
Output:
Enter numbers separated by spaces:
2 5 6 3 9 45 34 92 51
Output:
2 5 34 92
.
Input Format:
The first line contains the numbers of list A separated by a space.
Output Format:
Print the numbers in a single line separated by a space which are not multiples of 3.
Example:
Input:
1 2 3 4 5 6 5
Output:
1 2 4 5 5
Explanation:
Here the elements of A are 1, 2, 3, 4, 5, 6, 5 and since 3, 6 are the multiples of 3 hence after removing them the list becomes 1, 2, 4, 5, 5
Solution:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Enter numbers separated by spaces:") | |
inputStr = input() | |
strList = inputStr.split() | |
numList = [int(x) for x in strList] | |
print("Output:") | |
for x in numList: | |
if x % 3 != 0: | |
print(x,end=" ") |
Enter numbers separated by spaces:
2 5 6 3 9 45 34 92 51
Output:
2 5 34 92
.
No comments:
Post a Comment