• Sep 6, 2020 •C S
0 likes • 2 views
def Fibonacci(n): if n<0: print("Incorrect input") # First Fibonacci number is 0 elif n==1: return 0 # Second Fibonacci number is 1 elif n==2: return 1 else: return Fibonacci(n-1)+Fibonacci(n-2) # Driver Program print(Fibonacci(9))
• May 31, 2023 •CodeCatch
0 likes • 0 views
# Prompt user for a decimal number decimal = int(input("Enter a decimal number: ")) # Convert decimal to binary binary = bin(decimal) # Convert decimal to hexadecimal hexadecimal = hex(decimal) # Display the results print("Binary:", binary) print("Hexadecimal:", hexadecimal)
import itertools def compute_permutations(string): # Generate all permutations of the string permutations = itertools.permutations(string) # Convert each permutation tuple to a string permutations = [''.join(permutation) for permutation in permutations] return permutations # Prompt the user for a string string = input("Enter a string: ") # Compute permutations permutations = compute_permutations(string) # Display the permutations print("Permutations:") for permutation in permutations: print(permutation)
• Nov 18, 2022 •AustinLeath
0 likes • 8 views
#question1.py def rose(n) : if n==0 : yield [] else : for k in range(0,n) : for l in rose(k) : for r in rose(n-1-k) : yield [l]+[r]+[r] def start(n) : for x in rose(n) : print(x) #basically I am printing x for each rose(n) file print("starting program: \n") start(2) # here is where I call the start function
• Nov 19, 2022 •CodeCatch
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)
• 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])