can please someone help me with this assignment IT117 Recurs
can please someone help me with this assignment IT117 Recursion Comprehension homework 1 1 , Fibonacci sequence 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 ... is defined by the formula Fn = Fn-1 + Fn-2 for n 2 with F0 = 0 and F1 = 1. Compose a program to print the first n Fibo numbers. And try to do analysis about the computation burden of your recursive solution. 2, Climbing stair You are climbing a stair case. It takes n steps (Given n will be a positive integer.) to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Compose a program to explain your answer. 3. Palindrome Recursion. Implement the function is_palindrome, using recursion, such that it returns True if the argument s is a palindrome (ie, reads the same forwards and backwards), and False otherwise. You may assume that s is all lower case and doesn\'t any whitespace characters. Definition: A string is a palindrome if the first character is the same as the last, and the rest of the string is a palindrome; an empty string is a palindrome. $ python palindrome.py bolton False $ python palindrome.py amanaplanacanalpanama True 4. Binary conversion. Given two binary strings, return their sum (also a binary string). For example, a = \"11\" b = \"1\" Return “100\". 5 Permutations. Compose a program that takes a command-line argument n and writes all n! permutations of the n letters starting at a (assume that n is no greater than 26). A permutation of n elements is one of the n! possible orderings of the elements. As an example, when n = 3 you should get the following output. Do not worry about the order in which you enumerate them. bca cba cab acb bac abc 6 Permutations of size k. Modify your solution to the previous exercise so that it takes two commandline arguments n and k, and writes all P(n, k) = n! / (n-k)! permutations that contain exactly k of the n elements. Below is the desired output when k = 2 and n = 4. You need not write them in any particular order. ab ac ad ba bc bd ca cb cd da db dc 7 Combinations. Compose a program that takes one integer command-line argument n and writes all 2n combinations of any size. A combination is a subset of the n elements, independent of order. As an example, when n = 3 you should get the following output. a ab abc ac b bc c Note that the first element written is the empty string (subset of size 0). 8 Combinations of size k. Modify your solution to the previous exercise so that it takes two commandline arguments n and k, and writes all C(n, k) = n! / (k! * (n-k)!) combinations of size k. For example, when n = 5 and k = 3 you should get the following output. abc abd abe acd ace ade bcd bce bde cde 9 Scramble String. Given a string s1, we may represent it as a binary tree by partitioning it to two nonempty substrings recursively. Below is one possible representation of s1 = \"great\": great / \\ gr eat / \\ / \\ g r e at / \\ a t To scramble the string, we may choose any non-leaf node and swap its two children. For example, if we choose the node \"gr\" and swap its two children, it produces a scrambled string \"rgeat\". rgeat / \\ rg eat / \\ / \\ r g e at / \\ a t We say that \"rgeat\" is a scrambled string of “great\". Similarly, if we continue to swap the children of nodes \"eat\" and \"at\", it produces a scrambled string \"rgtae\". rgtae / \\ rg tae / \\ / \\ r g ta e / \\ t a We say that \"rgtae\" is also a scrambled string of \"great\". Given two strings s1 and s2 of the same length, compose a Python script to determine if s2 is a scrambled string of s1. ==================================================================================== Homework format: 1 Make sure your programs meet the input and output specifications by running the following command on the terminal (command line mode): $ python YourPythonProgram.py ... 2 Create a folder and named as your _. Save your python files (source files only, please remove pic files and other files) in your folder. Then, compress that folder to create _.zip file. For example, submission for Ryan Koh will be ryan_koh.zip.
Solution
## program to find N Fibonacci series
def fib(num):
firstNum=1;## assaigning fistnum and second number to be 1
secondNum=1;
count=2;## inisilising fibnacci number count
numcount=3;## number count (i.e which fibnacci)
if num<=0:## checking +ve num or not
print(\"Enter +ve Num:\")
elif num==1:## if given number only 1, gives first num
print(\"Nth Fibonacci number\")
print(\"The 1st Fibonacci Number is\",firstNum)
else:
print(\"Nth Fibonacci number\ \ \")
print(\"The\",1,\"st Fibonacci Number is \",firstNum)
print(\"The\",2,\"nd Fibonacci Number is \",secondNum)
while count<num:## loop runs until count<num
Nth = firstNum+secondNum## next Nth number will be adding firstnum and second num
print(\"The\",numcount,\"Th Fibonacci Number is \",Nth)## printing Nth num
numcount +=1
## updating values
firstNum=secondNum
secondNum=Nth
count += 1
def test():## tesing def
N=int(input(\"Enter Nth Term:\"))
fib(N)
##fib(20)
test()


