Advertisement
biswasrohit20

pyyy

Jun 9th, 2021
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.56 KB | None | 0 0
  1. # 5a
  2.  
  3. def enjoy_coding(paradigm):
  4.     if paradigm == "functional":
  5.         return ":-) :D"
  6.     if paradigm != "functional":
  7.         return ":( :C"
  8. print(enjoy_coding("functional"))
  9. print(enjoy_coding("imperative"))
  10.  
  11.  
  12.  
  13. # 5c 1
  14.  
  15. sum = 0
  16. for i in range(1,11):
  17.     sum += i
  18. print(sum)
  19.  
  20.  
  21. # 5c 2
  22.  
  23. def recurSum(n):
  24.     if n <= 1:
  25.         return n
  26.     return n + recurSum(n - 1)
  27.  
  28. n = 10
  29. print(recurSum(n))
  30.  
  31.  
  32. # 6a
  33.  
  34. def sum_if_positives(ints):
  35.     sum = 0
  36.     for i in ints:
  37.         if i > 0:
  38.             sum += i
  39.     return sum
  40.  
  41. # 6b
  42.  
  43. def sum_if_positives(nums):
  44.     total_positive_nums = list(filter(lambda nums:nums>0,nums))
  45.     return sum(total_positive_nums)
  46.  
  47. print(sum_if_positives(nums))
  48.  
  49.  
  50. #6 c
  51.  
  52. def isEven(num):
  53.     if num % 2 == 0:
  54.         return True
  55.  
  56. def printNums(numlist, func):
  57.     for i in numlist:
  58.         if func(i):
  59.             print(i)
  60.  
  61. printNums([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], isEven)
  62.  
  63.  
  64. # 7a
  65.  
  66. courseList = [('SDJ1', 5, 1), ('DNP1', 5, 1), ('SEP1', 10, 1),
  67.  ('SDJ2', 5, 2), ('SDJ3', 5, 3), ('PME1', 5, 6),
  68.  ('BPR1', 5, 6), ('PCL1', 5, 6), ('BPR2', 15, 7)]
  69.  
  70. def filter_for_6th_sem(clist):
  71.     courses_in_6th_sem = []
  72.     for course in courseList:
  73.         if course[2] == 6:
  74.             courses_in_6th_sem.append(course)
  75.     print(courses_in_6th_sem)
  76.  
  77. filter_for_6th_sem(courseList)
  78.  
  79.  
  80. # 7b
  81.  
  82. class StudentWorker:
  83.     pass
  84.  
  85. class Student(StudentWorker):
  86.     def __init__(self, sname, snumber):
  87.         self.sname = sname
  88.         self.snumber = snumber
  89.         self.courseList = []
  90.  
  91.     def addCourses(self, course):
  92.         self.courseList.append(course)
  93.  
  94.     def showCourses(self):
  95.         print(self.courseList)
  96.  
  97.  
  98. class Course:
  99.     def __init__(self, courseName, ects, semester):
  100.         self.courseName = courseName
  101.         self.ects = ects
  102.         self.semester = semester
  103.  
  104.     def display(self):
  105.         print(self.courseName, self.ects, self.semester)
  106.  
  107.  
  108. class Worker(StudentWorker):
  109.     def __init__(self, hoursWorked):
  110.         self.hoursWorked = hoursWorked
  111.  
  112.     def getSalary(self):
  113.         salary = self.hoursWorked*500
  114.         print(f'Salary = $ {salary}')
  115.  
  116.  
  117. worker1 = Worker(19)                 # Here 19 refers to 19 work hour
  118. worker1.getSalary()
  119.  
  120. student1 = Student("Rohit", 98564)
  121. print(student1.sname)
  122. print(student1.snumber)
  123. student1.addCourses("Basic Maths")
  124. student1.showCourses()
  125.  
  126.  
  127. course1 = Course("Advance Physics", 23, 4)
  128. print(course1.courseName)
  129. print(course1.ects)
  130. print(course1.semester)
  131.  
  132. student1.addCourses(course1)
  133. print(student1.courseList[-1].courseName)
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement