This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
SUBTRACTION_CONSTANT = 96 #ASCII value of 'a' - 1 | |
def getValueOfaWord(word) : | |
#Using ASCII values of characters to find value of a word | |
val = 0 | |
for letter in word : | |
val += ord(letter) - SUBTRACTION_CONSTANT | |
return val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Issue : The function `sort_priority` always returns False even if it finds a high-priority item. | |
Reason : The found variable is not declared as nonlocal hence the initial value, which is set as | |
false in outer function is not changed by the helper function. | |
Solution : 1. If the script uses only python3, simply declaring `found` as nonlocal in the helper | |
function by adding a line `nonlocal found` is enough. | |
2. If we want it to be compatible with python 2 also, we can not use nonlocal keyword as it is |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Intended Behaviour : The function extend_list(val,list) should extend the `list` and add `val` to the list or return | |
val as a new list if no `list` argument is given. | |
Issue : 1. If no value for `extended_list` argument is given to the function for more than one calls, it creates a | |
single new list on the first call and extends it for all the further calls. | |
2. The function only works if `val` is a single value. If a list is sent as `val` it will append the whole | |
list as a single value to the required list. | |
Solution : 1. The problem aries because in the first call with no value for `extended_list` argument a new list is created | |
and the list is used is used in the subsequent calls if no argument is given for `extended_list`. This can solved | |
by expicitly creating a new list inside the function which will be destroyed when the function calls ends. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
import gps | |
import requests | |
#Listen on port 2947 of gpsd | |
session = gps.gps("localhost", "2947") | |
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE) | |
while True : | |
rep = session.next() |