• Nov 18, 2022 •AustinLeath
0 likes • 5 views
# Python Program to calculate the square root num = float(input('Enter a number: ')) num_sqrt = num ** 0.5 print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))
• Jun 1, 2023 •CodeCatch
0 likes • 1 view
filename = "data.txt" with open(filename, "r") as file: file_contents = file.readlines() file_contents = [line.strip() for line in file_contents] print("File contents:") for line in file_contents: print(line)
• Nov 19, 2022 •CodeCatch
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 • 0 views
import math def factorial(n): print(math.factorial(n)) return (math.factorial(n)) factorial(5) factorial(10) factorial(15)
• Feb 23, 2025 •hasnaoui1
0 likes • 7 views
print("hello world")
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)