|
| 1 | +#Write a Python program to find all numbers between 1000 and 3000 (both included) such that each digit of the number is even, and then print them in a comma-separated sequence. |
| 2 | +even_numbers_range = [] |
| 3 | +for num in range(1000, 3001): |
| 4 | + str_num = str(num) |
| 5 | + if all(int(digit) % 2 == 0 for digit in str_num): |
| 6 | + even_numbers_range.append(str_num) |
| 7 | +print(",".join(even_numbers_range)) |
| 8 | +# # write a python program to take input from user and store in list and find odd and even numbers in the list and store them in separate lists |
| 9 | +# # and print the lists |
| 10 | +# Taking input from user |
| 11 | +# user_input = input("Enter numbers separated by spaces: ") |
| 12 | + |
| 13 | + |
| 14 | +# Splitting the input string into a list of numbers (as strings) |
| 15 | +# num_list = user_input.split() |
| 16 | +# Initializing empty lists for odd and even numbers |
| 17 | +# odd_numbers = [] |
| 18 | +# even_numbers = [] |
| 19 | +# Iterating through the list of numbers |
| 20 | +# for num_str in num_list: |
| 21 | +# num = int(num_str) # Converting string to integer |
| 22 | +# if num % 2 == 0: |
| 23 | +# even_numbers.append(num) # Appending to even numbers list |
| 24 | +# else: |
| 25 | +# odd_numbers.append(num) # Appending to odd numbers list |
| 26 | +# Printing the results |
| 27 | +# print("Even numbers:", even_numbers) |
| 28 | +# print("Odd numbers:", odd_numbers) |
| 29 | +# # Write a Python program to find all numbers between 1000 and 3000 (both included) such that each digit of the number is even, and then print them in a single line separated by commas. |
| 30 | +# even_numbers_range = [] |
| 31 | +# for num in range(1000, 3001): |
| 32 | +# str_num = str(num) |
| 33 | +# if all(int(digit) % 2 == 0 for digit in str_num |
| 34 | +# even_numbers_range.append(str_num) |
| 35 | +# print(",".join(even_numbers_range)) |
| 36 | +# # write a python program to take input from user and store in list and find odd and even numbers in the list and store them in separate lists |
| 37 | +# # and print the lists |
| 38 | +# Taking input from user |
| 39 | +# user_input = input("Enter numbers separated by spaces: ") |
| 40 | +# Splitting the input string into a list of numbers (as strings) |
| 41 | +# num_list = user_input.split() |
| 42 | +# Initializing empty lists for odd and even numbers |
| 43 | +# odd_numbers = [] |
| 44 | +# even_numbers = [] |
| 45 | +# Iterating through the list of numbers |
| 46 | +# for num_str in num_list: |
| 47 | +# num = int(num_str) # Converting string to integer |
| 48 | +# if num % 2 == 0: |
| 49 | +# even_numbers.append(num) # Appending to even numbers list |
| 50 | +# else: |
| 51 | +# odd_numbers.append(num) # Appending to odd numbers list |
| 52 | +# Printing the results |
| 53 | +# print("Even numbers:", even_numbers) |
| 54 | +# print("Odd numbers:", odd_numbers) |
| 55 | +# # Write a Python program to find all numbers between 1000 and 3000 (both included) such that each digit of the number is even, and then print them in a single line separated by commas. |
| 56 | +# even_numbers_range = [] |
| 57 | +# for num in range(1000, 3001): |
| 58 | +# str_num = str(num) |
| 59 | +# if all(int(digit) % 2 == 0 for digit in str_num): |
| 60 | +# even_numbers_range.append(str_num) |
| 61 | +# print(",".join(even_numbers_range)) |
| 62 | +# # write a python program to take input from user and store in list and find odd and even numbers in the list and store them in separate lists |
| 63 | +# # and print the lists |
| 64 | +# Taking input from user |
| 65 | +# user_input = input("Enter numbers separated by spaces: ") |
| 66 | +# Splitting the input string into a list of numbers (as strings) |
| 67 | +# num_list = user_input.split() |
| 68 | +# Initializing empty lists for odd and even numbers |
| 69 | +# odd_numbers = [] |
| 70 | +# even_numbers = [] |
| 71 | +# Iterating through the list of numbers |
| 72 | +# for num_str in num_list: |
| 73 | +# num = int(num_str) # Converting string to integer |
| 74 | +# if num % 2 == 0: |
| 75 | +# even_numbers.append(num) # Appending to even numbers list |
| 76 | +# else: |
| 77 | +# odd_numbers.append(num) # Appending to odd numbers list |
| 78 | +# Printing the results |
| 79 | +# print("Even numbers:", even_numbers) |
| 80 | +# print("Odd numbers:", odd_numbers) |
0 commit comments