Facebook
From Monkey d liffy, 6 Months ago, written in Python.
This paste is a reply to Re: op out of ur legue from monkey d luffy - view diff
Embed
Download Paste or View Raw
Hits: 279
  1. Write a recursive function to print the factorial for a given number.
  2. def recur_factorial(n):
  3. if n==1:
  4. return
  5. n
  6. else:
  7. return n*recur_factorial(n-1)
  8. num=int(input("Enter Number"))
  9. if num<0:
  10. print("Enter valid number")
  11. elif num==0:
  12. print("factorial of 0 is 1")
  13. else:
  14. print("The factorial of",num,"is",recur_factorial(num))
  15. Enter Number 5
  16. The factorial of 5 is 120
  17.  
  18.  
  19. a. Write a function that takes a character (i.e. a string of length 1) and returns True if it is a vowel,
  20. False otherwise.
  21. def isvowel(char):
  22. all_vowel='aeiou'
  23. return char in all_vowel
  24. print(isvowel('a"))
  25. print(isvowel('b'))
  26.  
  27.  
  28.  
  29. b. Define a function that computes the length of a given list or string
  30. def len(s):
  31. counter=0
  32. for i in S:
  33. counter+=1
  34. return counter
  35. s=input("enter string:")
  36. print(len(s))
  37.  
  38.  
  39. b. Define a function that computes the length of a given list or string
  40. def len(s):
  41. counter=0
  42. for i in S:
  43. counter+=1
  44. return counter
  45. s=input("enter string:")
  46. print(len(s))
  47.  
  48.  
  49.  
  50. C.
  51. example, histogram ([4, 9, 9, 7]) 7]) should print the following:
  52. ****
  53. def histogram(items):
  54. for n in items:
  55. output=''
  56. times=n
  57. while times>0:
  58. output+='*'
  59. times=times-1
  60. þprintCoutput)
  61. histogram([4,9,7])
  62.  
  63.  
  64.  
  65. Design a class that store the information of student and display the same
  66. class student:
  67. def info(self,name,city):
  68. name=input("Enter name:")
  69. city=input("Enter city:")
  70. print("Name:",name,"City:",city)
  71. 1/4
  72. :::
  73. obj=student()
  74. obj.info('Name','City')
  75. Enter name:Bob
  76. Enter city:Atlanta
  77. Name: Bob City: Atlanta
  78.  
  79.  
  80.  
  81.  
  82. b. Implement the concept of inheritance using python
  83. Note: Create polygon.py, rectangle.py and inherit.py file in same project run the inherit project
  84. class polygon:
  85. width=0
  86. height=0
  87. def set_values(self,width,height):
  88. polygon.width=width
  89. polygon.height=height
  90. Python Programming Practical
  91. S.Y.B.Sc (IT)
  92. from polygon import*
  93. class rectangle(polygon)
  94. def area(self):
  95. return self.width*self.height
  96. from Rectangle import*
  97. rect=rectangle()
  98. rect.set_values(10,10)
  99. print("Area of Rectangle:",rect.area())
  100. Area of Rectangle: 100
  101.  
  102.  enjoy

Replies to op out of ur legue op rss

Title Name Language When
Re: op out of ur legue op Rajubhai python 6 Months ago.
Re: op out of ur legue op Suraj python 6 Months ago.