Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 5a
- def enjoy_coding(paradigm):
- if paradigm == "functional":
- return ":-) :D"
- if paradigm != "functional":
- return ":( :C"
- print(enjoy_coding("functional"))
- print(enjoy_coding("imperative"))
- # 5c 1
- sum = 0
- for i in range(1,11):
- sum += i
- print(sum)
- # 5c 2
- def recurSum(n):
- if n <= 1:
- return n
- return n + recurSum(n - 1)
- n = 10
- print(recurSum(n))
- # 6a
- def sum_if_positives(ints):
- sum = 0
- for i in ints:
- if i > 0:
- sum += i
- return sum
- # 6b
- def sum_if_positives(nums):
- total_positive_nums = list(filter(lambda nums:nums>0,nums))
- return sum(total_positive_nums)
- print(sum_if_positives(nums))
- #6 c
- def isEven(num):
- if num % 2 == 0:
- return True
- def printNums(numlist, func):
- for i in numlist:
- if func(i):
- print(i)
- printNums([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], isEven)
- # 7a
- courseList = [('SDJ1', 5, 1), ('DNP1', 5, 1), ('SEP1', 10, 1),
- ('SDJ2', 5, 2), ('SDJ3', 5, 3), ('PME1', 5, 6),
- ('BPR1', 5, 6), ('PCL1', 5, 6), ('BPR2', 15, 7)]
- def filter_for_6th_sem(clist):
- courses_in_6th_sem = []
- for course in courseList:
- if course[2] == 6:
- courses_in_6th_sem.append(course)
- print(courses_in_6th_sem)
- filter_for_6th_sem(courseList)
- # 7b
- class StudentWorker:
- pass
- class Student(StudentWorker):
- def __init__(self, sname, snumber):
- self.sname = sname
- self.snumber = snumber
- self.courseList = []
- def addCourses(self, course):
- self.courseList.append(course)
- def showCourses(self):
- print(self.courseList)
- class Course:
- def __init__(self, courseName, ects, semester):
- self.courseName = courseName
- self.ects = ects
- self.semester = semester
- def display(self):
- print(self.courseName, self.ects, self.semester)
- class Worker(StudentWorker):
- def __init__(self, hoursWorked):
- self.hoursWorked = hoursWorked
- def getSalary(self):
- salary = self.hoursWorked*500
- print(f'Salary = $ {salary}')
- worker1 = Worker(19) # Here 19 refers to 19 work hour
- worker1.getSalary()
- student1 = Student("Rohit", 98564)
- print(student1.sname)
- print(student1.snumber)
- student1.addCourses("Basic Maths")
- student1.showCourses()
- course1 = Course("Advance Physics", 23, 4)
- print(course1.courseName)
- print(course1.ects)
- print(course1.semester)
- student1.addCourses(course1)
- print(student1.courseList[-1].courseName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement