## Fibonacci Series

0 likes • Nov 18, 2022
Python

## More Python Posts

```# Function to check Armstrong numberdef is_armstrong_number(number):    # Convert number to string to iterate over its digits    num_str = str(number)        # Calculate the sum of the cubes of each digit    digit_sum = sum(int(digit) ** len(num_str) for digit in num_str)        # Compare the sum with the original number    if digit_sum == number:        return True    else:        return False
# Prompt user for a numbernumber = int(input("Enter a number: "))
# Check if the number is an Armstrong numberif is_armstrong_number(number):    print(number, "is an Armstrong number.")else:    print(number, "is not an Armstrong number.")```
```mydict = {'carl':40, 'alan':2, 'bob':1, 'danny':0}
# How to sort a dict by value Python 3>sort = {key:value for key, value in sorted(mydict.items(), key=lambda kv: (kv, kv))}print(sort)
# How to sort a dict by key Python 3>sort = {key:mydict[key] for key in sorted(mydict.keys())}print(sort)```
```#question1.pydef rose(n) :  if n==0 :     yield []  else :    for k in range(0,n) :          for l in rose(k) :        for r in rose(n-1-k) :                  yield [l]+[r]+[r]            def start(n) :  for x in rose(n) :       print(x) #basically I am printing x for each rose(n) file

print("starting program: \n")start(2) # here is where I call the start function```
`x[cat_var].isnull().sum().sort_values(ascending=False)`
`#Loop back to this point once code finishesloop = 1while (loop < 10):#All the questions that the program asks the user    noun = input("Choose a noun: ")    p_noun = input("Choose a plural noun: ")    noun2 = input("Choose a noun: ")    place = input("Name a place: ")    adjective = input("Choose an adjective (Describing word): ")    noun3 = input("Choose a noun: ")#Displays the story based on the users input    print ("------------------------------------------")    print ("Be kind to your",noun,"- footed", p_noun)    print ("For a duck may be somebody's", noun2,",")    print ("Be kind to your",p_noun,"in",place)    print ("Where the weather is always",adjective,".")    print ()    print ("You may think that is this the",noun3,",")    print ("Well it is.")    print ("------------------------------------------")#Loop back to "loop = 1"    loop = loop + 1`
```class Solution(object):    def floodFill(self, image, sr, sc, newColor):        R, C = len(image), len(image)        color = image[sr][sc]        if color == newColor: return image        def dfs(r, c):            if image[r][c] == color:                image[r][c] = newColor                if r >= 1: dfs(r-1, c)                if r+1 < R: dfs(r+1, c)                if c >= 1: dfs(r, c-1)                if c+1 < C: dfs(r, c+1)
dfs(sr, sc)        return image```