Program to print all the numbers divisible by 3 and 5 for a given number in python

Program to print all the numbers divisible by 3 and 5 for a given number in python

If you want to print all numbers up to a given number n that are divisible by both 3 and 5, you can use a loop and a conditional check. Here's how you can do it:

def print_divisible_by_3_and_5(n): for i in range(1, n + 1): if i % 3 == 0 and i % 5 == 0: print(i) # Example usage: n = int(input("Enter a number: ")) print_divisible_by_3_and_5(n) 

If you run the program and input 100, for example, it will print numbers like 15, 30, 45, and so on up to 100. These numbers are divisible by both 3 and 5.


More Tags

asp-net-config-builders jaxb multi-select poi-hssf oracleapplications oracle10g cloudinary firemonkey ssms primeng-datatable

More Programming Guides

Other Guides

More Programming Examples