Write a recursive function to print the factorial for a given number.
def recur_factorial(n):
if n==1:
return
n
else:
return n*recur_factorial(n-1)
num=int(input("Enter Number"))
if num<0:
print("Enter valid number")
elif num==0:
print("factorial of 0 is 1")
else:
print("The factorial of",num,"is",recur_factorial(num))
Enter Number 5
The factorial of 5 is 120
a. Write a function that takes a character (i.e. a string of length 1) and returns True if it is a vowel,
False otherwise.
def isvowel(char):
all_vowel='aeiou'
return char in all_vowel
print(isvowel('a"))
print(isvowel('b'))
b. Define a function that computes the length of a given list or string
def len(s):
counter=0
for i in S:
counter+=1
return counter
s=input("enter string:")
print(len(s))
b. Define a function that computes the length of a given list or string
def len(s):
counter=0
for i in S:
counter+=1
return counter
s=input("enter string:")
print(len(s))
C.
example, histogram ([4, 9, 9, 7]) 7]) should print the following:
****
def histogram(items):
for n in items:
output=''
times=n
while times>0:
output+='*'
times=times-1
þprintCoutput)
histogram([4,9,7])
Design a class that store the information of student and display the same
class student:
def info(self,name,city):
name=input("Enter name:")
city=input("Enter city:")
print("Name:",name,"City:",city)
1/4
:::
obj=student()
obj.info('Name','City')
Enter name:Bob
Enter city:Atlanta
Name: Bob City: Atlanta
b. Implement the concept of inheritance using python
Note: Create polygon.py, rectangle.py and inherit.py file in same project run the inherit project
class polygon:
width=0
height=0
def set_values(self,width,height):
polygon.width=width
polygon.height=height
Python Programming Practical
S.Y.B.Sc (IT)
from polygon import*
class rectangle(polygon)
def area(self):
return self.width*self.height
from Rectangle import*
rect=rectangle()
rect.set_values(10,10)
print("Area of Rectangle:",rect.area())
Area of Rectangle: 100
enjoy
Replies to op out of ur legue op
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}