• Nov 19, 2022 •CodeCatch
0 likes • 1 view
from functools import partial def curry(fn, *args): return partial(fn, *args) add = lambda x, y: x + y add10 = curry(add, 10) add10(20) # 30
0 likes • 6 views
# function which return reverse of a string def isPalindrome(s): return s == s[::-1] # Driver code s = "malayalam" ans = isPalindrome(s) if ans: print("Yes") else: print("No")
0 likes • 0 views
from time import sleep def delay(fn, ms, *args): sleep(ms / 1000) return fn(*args) delay(lambda x: print(x), 1000, 'later') # prints 'later' after one second
• Jul 24, 2024 •AustinLeath
0 likes • 3 views
from statistics import median, mean, mode def print_stats(array): print(array) print("median =", median(array)) print("mean =", mean(array)) print("mode =", mode(array)) print() print_stats([1, 2, 3, 3, 4]) print_stats([1, 2, 3, 3])
• Jun 1, 2023 •CodeCatch
0 likes • 2 views
from colorama import init, Fore # Initialize colorama init() print(Fore.RED + "This text is in red color.") print(Fore.GREEN + "This text is in green color.") print(Fore.BLUE + "This text is in blue color.") # Reset colorama print(Fore.RESET + "This text is back to the default color.")
0 likes • 10 views
""" Currency Converter ---------------------------------------- """ import urllib.request import json def currency_converter(currency_from, currency_to, currency_input): yql_base_url = "https://query.yahooapis.com/v1/public/yql" yql_query = 'select%20*%20from%20yahoo.finance.xchange%20where%20pair' \ '%20in%20("'+currency_from+currency_to+'")' yql_query_url = yql_base_url + "?q=" + yql_query + "&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys" try: yql_response = urllib.request.urlopen(yql_query_url) try: json_string = str(yql_response.read()) json_string = json_string[2: json_string = json_string[:-1] print(json_string) yql_json = json.loads(json_string) last_rate = yql_json['query']['results']['rate']['Rate'] currency_output = currency_input * float(last_rate) return currency_output except (ValueError, KeyError, TypeError): print(yql_query_url) return "JSON format error" except IOError as e: print(str(e)) currency_input = 1 #currency codes : http://en.wikipedia.org/wiki/ISO_4217 currency_from = "USD" currency_to = "TRY" rate = currency_converter(currency_from, currency_to, currency_input) print(rate)