Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 89
Kernel: Python 3 (system-wide)
def grade_students(dic_in): for students in dic_in: # sum(dic_in[students]) total_value = 0 for x in dic_in[students]: total_value += x avg = total_value / len(dic_in[students]) if avg >= 90: y = 'A' elif avg >= 80: y = 'B' elif avg >= 70: y = 'C' elif avg >= 60: y = 'D' elif avg < 60: y = 'F' dic_in[students] = y
class Folder: def __init__(self, name, owner, files): self.name = name self.owner = owner self.files = files def get_name(self): return self.name def set_name(self, name): self.name = name def __add__(self, other): add_files = self.files for file in other.files: if not file in self.files: add_files.append(file) return Folder(self.name, self.owner, add_files)
class Media: def __init__(self, title="Unknown", year=0): self.title = title self.year = year def getTitle(self):class Folder: def __init__(self, name, owner, files): self.name = name self.owner = owner self.files = files def get_name(self): return self.name def set_name(self, name): self.name = name def __add__(self, other): add_files = self.files for file in other.files: if not file in self.files: add_files.append(file) return Folder(self.name, self.owner, add_files) return self.title def get_year(self): return self.year def __repr__(self): return "Title: {}\nPublication Date: {}".format(self.title, self.year) class Book(Media): def __init__(self, title="", year=0, ISBN = 0): super().__init__(title, year) self.ISBN = ISBN def getISBN(self): return self.ISBN def __repr__(self): return "Title: {}\nYear: {}\nISBN: {}".format(self.title,self.year,self.ISBN)
class Time: def __init__(self, hours=0, minutes=0): self.hours = hours self.minutes = minutes def set_hours(self, hours): self.hours = hours def set_minutes(self, minutes): self.minutes = minutes def get_time(self): return (self.hours,self.minutes) def __str__(self): return "{}:{}".format(self.hours,self.minutes) def __add__(self, minutes): num_minutes = minutes % 60 num_hours = (minutes - num_minutes) // 60 self.minutes += num_minutes self.hours += num_hours while self.minutes >= 60: self.minutes -= 60 self.hours += 1 if self.hours >= 24: self.hours = self.hours % 24 def __lt__(self, other): self_total = self.minutes + self.hours * 60 other_total = other.minutes + other.hours * 60 if self_total < other_total: return True else: return False class FlightArrival(Time): def __init__(self, hours, minutes, orig_city, flight_str): super().__init__(hours,minutes) self.orig_city = orig_city self.flight_str = flight_str def get_orig_city(self): return self.orig_city def __str__(self): return "{} {} ETA: {}:{}".format(self.flight_str, self.orig_city, self.hours, self.minutes) def schedule(time_list): sort_list = [] test_list = time_list[:] while len(test_list) > 0: sort_list.append(min(test_list)) test_list.remove(min(test_list)) return sort_list
def countEs(string): if len(string) == 0: return 0 elif string[0] == 'e': return 1 + countEs(string[1:]) else: return countEs(string[1:]) def minEs(name_list): if len(name_list) == 1: return name_list elif countEs(name_list[0]) >= countEs(name_list[1]): name_list.remove(name_list[0]) return minEs(name_list) else: name_list.remove(name_list[1]) return minEs(name_list)
def times_index(lst): if len(lst) == 0: return [] else: return times_index(lst[:-1]) + [(lst[len(lst)-1] * (len(lst)-1))] # [1] + [2] = [1,2]
ls = [3, 2.4, 9.1, 10] times_index(ls)
[0, 2.4, 18.2, 30]