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
assert( | |
speed >= 0, | |
"Speed should be non-negative!" | |
) |
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
def get_speed(final, init, time_taken): | |
speed = (final - init) / time_taken # simple equation could return negative value if init > final. | |
assert speed >= 0, "Speed can't be negative" # will raise an AssertionError exception if speed is less than 0. | |
return speed |
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
def get_speed(final, init, time_taken): | |
speed = (final - init) / time_taken # simple equation could return negative value if init > final. | |
if speed < 0: | |
#do something eg raise exception or warn user. | |
return speed | |
print(get_speed(5, 2, 1)) # will return 3 as expected | |
print(get_speed(2, 5, 1)) # will raise AssertionError exception |
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
def get_speed(final, init, time_taken): | |
speed = (final - init) / time_taken # simple equation could return negative value if init > final. | |
assert speed >= 0 # will raise an AssertionError exception if speed is less than 0. | |
return speed | |
print(get_speed(5, 2, 1)) # will return 3 as expected | |
print(get_speed(2, 5, 1)) # will raise AssertionError exception |
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
""" | |
Simple Telegram Bot to automate the process of obtaining Outline.com links. | |
Created by Raivat Shah in 2019. | |
""" | |
# Imports | |
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters | |
import logging | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys |
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
{ | |
"first name":"John", | |
"last name":"Appleseed", | |
"age":30, | |
"house":{ | |
"address":{ | |
"house no":"D12", | |
"street":"College Ave East", | |
"city":"Singapore" | |
}, |
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
"""Sentiment analyser for Data Journalism Feedback""" | |
import csv | |
from textblob import TextBlob | |
data_source = 'sentence.csv' | |
with open(data_source, 'r') as csvfile: | |
rows = csv.reader(csvfile) | |
for row in rows: | |
sentence = row[0] |
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
import signal | |
import sys | |
from google.cloud import language | |
from google.api_core.exceptions import InvalidArgument | |
# create a Google Cloud Natural Languague API Python client | |
client = language.LanguageServiceClient() | |
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
//2A | |
function is_odd(i) { | |
if (i % 2 === 0) { | |
return false; | |
} else { | |
return true; | |
} | |
} | |
//Test cases |
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
//Questions from Avenger Ken. | |
//5.1 Math Floor - modify / operator to round down the answer. parse_and_evaluate("5/2;"); returns 2 and not 2.5 | |
//Simple: Modify Built in operator of MCE (lines 728 to 750) | |
const builtin_functions = list( | |
pair("pair", pair ), | |
pair("head", head ), | |
pair("tail", tail ), |
NewerOlder