diff --git a/Python/Program43/Program43.py b/Python/Program43/Program43.py index e69de29b..a9ab2d9a 100644 --- a/Python/Program43/Program43.py +++ b/Python/Program43/Program43.py @@ -0,0 +1,11 @@ +terms = 10 + +# Uncomment code below to take input from the user +# terms = int(input("How many terms? ")) + +# use anonymous function +result = list(map(lambda x: 2 ** x, range(terms))) + +print("The total terms are:",terms) +for i in range(terms): + print("2 raised to power",i,"is",result[i]) \ No newline at end of file diff --git a/Python/Program44/Program44.py b/Python/Program44/Program44.py index e69de29b..d4a2443f 100644 --- a/Python/Program44/Program44.py +++ b/Python/Program44/Program44.py @@ -0,0 +1,6 @@ +dec = 344 + +print("The decimal value of", dec, "is:") +print(bin(dec), "in binary.") +print(oct(dec), "in octal.") +print(hex(dec), "in hexadecimal.") \ No newline at end of file diff --git a/Python/Program45/Program45.py b/Python/Program45/Program45.py new file mode 100644 index 00000000..53396b4e --- /dev/null +++ b/Python/Program45/Program45.py @@ -0,0 +1,15 @@ +def recur_fibo(n): + if n <= 1: + return n + else: + return(recur_fibo(n-1) + recur_fibo(n-2)) + +nterms = 10 + +# check if the number of terms is valid +if nterms <= 0: + print("Plese enter a positive integer") +else: + print("Fibonacci sequence:") + for i in range(nterms): + print(recur_fibo(i)) \ No newline at end of file diff --git a/Python/Program45/Readme.md b/Python/Program45/Readme.md new file mode 100644 index 00000000..11d0c44d --- /dev/null +++ b/Python/Program45/Readme.md @@ -0,0 +1 @@ +# Python program to display the Fibonacci sequence \ No newline at end of file