Lena is planning a number game for her younger brother, Max. She wants to list all the numbers within a given range that either end in 7 or are multiples of 7. Help Lena by writing a program that takes the lower and upper bounds of the range and prints these special numbers.Input format :The input consists of two space-separated integers L and U, representing the lower and upper bounds of the range.Output format :The output prints the special numbers from the given range (both lower and upper range inclusive), separated by space.Refer to the sample output for formatting specifications.Code constraints :1 ≤ L, U ≤ 150L < USample test cases :Input 1 :7 17Output 1 :7 14 17 Input 2 :23 69Output 2 :27 28 35 37 42 47 49 56 57 6
Question
Lena is planning a number game for her younger brother, Max. She wants to list all the numbers within a given range that either end in 7 or are multiples of 7. Help Lena by writing a program that takes the lower and upper bounds of the range and prints these special numbers.Input format :The input consists of two space-separated integers L and U, representing the lower and upper bounds of the range.Output format :The output prints the special numbers from the given range (both lower and upper range inclusive), separated by space.Refer to the sample output for formatting specifications.Code constraints :1 ≤ L, U ≤ 150L < USample test cases :Input 1 :7 17Output 1 :7 14 17 Input 2 :23 69Output 2 :27 28 35 37 42 47 49 56 57 6
Solution
Here is a Python program that accomplishes the task:
def special_numbers(L, U):
for i in range(L, U+1):
if i % 10 == 7 or i % 7 == 0:
print(i, end=' ')
# Test the function
special_numbers(7, 17)
print()
special_numbers(23, 69)
This program defines a function special_numbers that takes two arguments, L and U, representing the lower and upper bounds of the range. It then iterates over all numbers in this range (inclusive). For each number, it checks if the number ends in 7 (i.e., if the remainder when divided by 10 is 7) or if the number is a multiple of 7 (i.e., if the remainder when divided by 7 is 0). If either condition is true, it prints the number, followed by a space. The end=' ' argument to the print function ensures that a space is printed after each number, rather than a newline.
The program then tests this function with the provided sample inputs.
Similar Questions
Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. That list is followed by two more integers representing lower and upper bounds of a range. Your program should output all integers from the list that are within that range (inclusive of the bounds). For coding simplicity, follow each output integer by a comma, even the last one. The output ends with a newline.Ex: If the input is:5 25 51 0 200 330 50then the output is:25,0,33,(the bounds are 0-50, so 51 and 200 are out of range and thus not output).To achieve the above, first read the list of integers into a vector.
Arun is tasked with creating a program that prints prime numbers within a given range. The program should take two integers, start and end, as input, and output the prime numbers between these two values (inclusive).Help Arun to complete the task using a 'for' loop.Input format :The input consists of two space-separated integers L and U, representing the starting range and ending range of the prime numbers.Output format :The output prints the prime numbers from the given starting range to the ending range separated by space.Refer to the sample output for formatting specifications.Code constraints :1 ≤ L, U ≤ 150L < USample test cases :Input 1 :1 23Output 1 :2 3 5 7 11 13 17 19 23 Input 2 :23 69Output 2 :23 29 31 37 41 43 47 53 59 61
write a program that performs bitwise AND between 7 and the number given by Alice and prints the result.
Write a program to print the multiples of given N within the rangeInput FormatThree space separated integers - 'N', 'start' and 'end'Output FormatPrint the multiple of given N within the range.Sample Input 15 1 10Sample Output 15 10 15 20 25 30 35 40 45 50Sample Input 25 10 15Sample Output 250 55 60 65 70 75
3.Question 3Which code prints all numbers from 3 to 7?1 pointfor i in range(8): print(i)for i in range(3, 4, 5, 6, 7): print(i)for i in range(3, 8): print(i)for i in range(3, 7): print(i)
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.