Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import floor
- from itertools import starmap, cycle
- # taxi_fare
- def compute_fare(average_speed, travel_time):
- average_speed /= 60
- fare = 40
- fare += 13.50*floor(average_speed*travel_time)
- fare += 2*floor(travel_time)
- return fare
- # GWA_calculator
- def calculate_GWA(courses):
- total_units = gwa = 0
- for course in courses:
- units = course[1]
- grade = course[2]
- if '(' in units and ')' in units:
- continue
- if grade in ['P','F','INC','']:
- continue
- total_units += float(units)
- gwa += eval(units + '*' + grade)
- if total_units == 0 or gwa == 0:
- return ''
- gwa /= total_units
- return str(round(gwa,2))
- # vigenere_cipher
- def vigenere_encrypt(message, key):
- join_message = ''.join(message.split(' '))
- cipher = ''.join(starmap(lambda x,y:chr((ord(x) + ord(y) - 130)%26 + 65), zip(join_message, cycle(key))))
- x = 0
- spaced_cipher = ''
- for i in message:
- if i == ' ':
- spaced_cipher += ' '
- continue
- spaced_cipher += cipher[x]
- x += 1
- print(spaced_cipher)
- return spaced_cipher
- # vigenere_cipher, no starmap nor cycle
- def vigenere_encrypt_conventional(message, key):
- key_char = 0
- cipher = ''
- for letter in message:
- if key_char == len(key):
- key_char = 0
- if letter == ' ':
- cipher += ' '
- else:
- cipher += chr((ord(letter) + ord(key[key_char]) - 130)%26 + 65)
- key_char += 1
- return cipher
- # keyed sorting
- f1 = lambda x: (int(str(x).split('.')[1][0]), x)
- f2 = lambda x: (int(str(x**3)[-2:]), x)
- f3 = lambda x: (len(x), x)
- f4 = lambda x: (sum(map(ord, x)), x)
- f5 = lambda x: (x[1], x[0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement