WAF to print the Fibonacci Series upto N
def fibonacci(n):
first=0
second=1
print("Fibonacci series:")
print(first,second,end=' ')
for i in range(2,n):
third=first+second
print(third,end=' ')
first=second
second=third
n=int(input("Enter the range:"))
fibonacci(n)
WAF to check the Armstrong number or not
def Armstrong(n):
num=n
sum=0
while n>0:
rem=n%10
sum=sum+rem**3
n=n//10
if num==sum:
print("Armstrong number")
else:
print("Not an Armstrong mumber")
n=int(input("Enter a number:"))
Armstrong(n)
WAF to print multiplication table of a given number
def Table(n):
for i in range(1,11):
print(n,'X', i,'=',n*i)
n=int(input("Enter a number:"))
Table(n)
WAF to print the series
111
22
def series():
for i in range(1,4):
for j in range(i,4):
print(i , end=' ')
print()
series()
WAF to print the series
AB
ABC
def series():
for i in range(65,68):
for j in range(65,i+1):
print(chr(j),end=' ')
print()
series()
#WAF to count and display the total even and odd numbers from a list
def Evenlist(L):
even=odd=0
for i in L:
if i%2==0:
even=even+1
else:
odd=odd+1
print("Totel even nos.=",even)
print("Totel odd nos.=",odd)
L=eval(input("Enter a list:"))
Evenlist(L)
#WAF to count and display the total vowels and consonants from a string
def Vowelcons(string):
vow=cons=0
for i in string:
if i.isalpha():
if i in 'AEIOUaeiou':
vow+=1
else:
cons+=1
print("No. of vowels=",vow)
print("No. of consonants=",cons)
string=input("Enter a string:")
Vowelcons(string)