pythonrecursionfizzbuzz# Finding multiples using recursion

Given 1 to 100 numbers, for multiples of 3 it should print "he" ,for multiples of 5 it should print "llo" ,for both multiples of 3 and 5 it should print "hello".

This is what I have:

```
for i in range (1,100):
if(i%3==0):
print("he")
elif(i%5==0):
print("llo")
elif(i%3==0 and i%5==0):
print("hello")
```

How would I do this recursively?

Solution

How about the code below?

```
def find_multiples(current, last_num=100):
# Base Case
if current > last_num:
return
result = ""
if current % 3 == 0:
result += "he"
if current % 5 == 0:
result += "llo"
if result:
print(f"{current}: {result}")
find_multiples(current+1, last_num)
find_multiples(1)
```

Base case is if `current`

reaches `last_num`

or the maximum number you'd like to check.

- Convert from Cartesian grid to Lat Lon python
- How to extract text from powerpoint text boxes, in their order within the presentation using python-pptx.
- why does floatformat:2 adds a comma after the hundred place
- Resetting value when another value switches sign
- XML to DATAFRAME and back to XML in python
- Python, Webiopi and Raspberry Pi
- Using datetime.timedelta to add years
- Python/Calling python scripts within bash terminal: What exactly happens when user presses Ctrl-C?
- Block reduce (downsample) 3D array with mode function
- Run slow Pytest commands at the end of the test suite
- Switch Row/Column on a chartsheet using openpyxl
- Disable silent types conversions in numpy
- How can I import a local module using Databricks asset bundles?
- How to exclude double values in sklearn.metrics.pairwise.euclidean_distances results
- BeautifulSoup can't parse a webpage?
- Printing different values within class in Python
- Scraping hierarchical website in a specific category
- Pydantic - apply validator on all fields of specific type
- Python program reacting to an event
- Convert date to datetime in Python
- Multidimensional indexing in Numpy with tuples as indices for certain axes
- Generating DKIM signatures VIA Python for Custom MTA
- pytorch split array by list of indices
- Creating new columns using for loop based on logical expression in Python
- Python print function stopped working after installing super-gradients in Google Colab
- How to extract the integer from the string '$61.52' to use in the arithmetic oprations in python?
- How can I select the proper openai.api_version?
- What's the use of /256 and %256 in it and how is the address divided into hi and lo bits?
- as_index=False groupBy doesn't work with count
- Calling SHGetKnownFolderPath from Python?