• Home
  • Blog
  • Python 3 Questiones (write the program)

Python 3 Questiones (write the program)

0 comments

Requirement:

1. You cannot import any module

2. The programs must be solved by Recursion 

3. Please use Python 3

—————————————–

Question 1: Write a program that asks the user for a binary string that also contains x’s. A binary string is a sequence of 1’s and 0’s. Your program should display all possible binary strings where the x’s can be replaced with either 1’s or 0’s. 

a. Examples

Enter a binary string: 1011

1011

Enter a binary string: 10×0 

1000
1010

Enter a binary string: xx0x

0000

0001

0100

0101

1000

1001

1100

1101

Question 2:

1.Write a program that is called funa() that implements the following function (part a&b below)

2.Write one more program that also is called funa() that implements the same function from last question but only makes one recursive call per recursion.

a.

funa(0)=1

funa(1)=2

funa(2)=3

funa(3)=4

funa(n)= funa(n−1)+ funa(n−3)+ funa(n−4) 

b. Examples

Enter a value for n: 3 
funa(3) = 4
Enter a value for n: 15
funa(15) = 1428
Enter a value for n: 5
funa(5) = 12

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}