#Fibonacci series
num = int(input("Enter a number "))
n1 = 0
n2= 1
print("Fibonacci series", n1,n2,end = " ")
for i in range(2,num):
n3=n1+n2
n1=n2
n2=n3
print(n3,end=" ")
Enter a number 10 Fibonacci series 0 1 1 2 3 5 8 13 21 34
#Armstrong number
num = int(input("Enter a number "))
sum = 0
temp = num
while temp>0:
digit= temp%10
sum += digit**3
temp//=10
if num==sum:
print(num, "is a Armstrong number")
else:
print(num, "is not a Armstrong number")
Enter a number 153 153 is a Armstrong number
#Assignment three
#longest word
def longest_word(words_list):
word_len = []
for n in words_list:
word_len.append((len(n), n))
word_len.sort()
return word_len[-1][0],word_len[-1][1]
result = longest_word(["PHP","Exercises","Backend"])
print("\nLongest word",[1])
print("Length of Longest word",result[0])
def find_longest_word(words_list):
word_len = []
for n in words_list:
word_len.append((len(n), n))
word_len.sort()
return word_len[-1][0], word_len[-1][1]
result = find_longest_word(["PHP", "Exercises", "Backend"])
print("\nLongest word: ",result[1])
print("Length of the longest word: ",result[0])
Longest word [1] Length of Longest word 9 Longest word: Exercises Length of the longest word: 9
#sort of lexicographical
def lexico_sort(s):
return sorted(sorted(s))
print(lexico_sort('python'))
['h', 'n', 'o', 'p', 't', 'y']
#Remove spaces from string
string = "Python is programming Language"
nospaces = string.replace(" ","")
print(nospaces)
PythonisprogrammingLanguage
def remove(string,n):
first = string[:n]
last = string[n+1:]
return first+last
string = input("Enter a string: ")
n= int(input("Enter the index of character to remove:"))
print("Modified string is: ")
print(remove(string,n))
Enter a string: hello Enter the index of character to remove3 Modified string: helo