Ask Python Expert

Assignment

1. (a) Explain in English what the following function will do. Explain how it works.

def whoknows(x):
      if (x<2):
          print(x)
      else:
          y = x//2
          whoknows(y)
          print(x%2)

(b) What will be the output if the following calls are made:

whoknows(2) =
whoknows(15) =
whoknows(-3) =

(c) Write a function digitize (using loops) that takes two parameters: one integer parameter and one bool parameter. The function would print the integer one digit at a time each on a separate line. If the bool parameter passed were true, the function would print the digits from the most significant digit to the least significant. Otherwise, it would print it in the reverse order (least significant to most significant).

Function Call

Output

digitize(1758,true)

1

 

7

 

5

 

8

digitize(1758,false)

8

 

5

 

7

 

1

(d) Write a function (without using loops) that reverses the digits in an integer and prints out the integer in this reverse form. It is not necessary to calculate the value of the reverse integer, just print out the digits in reverse order. The function should be called reverse. Remember to explain your functions, either by adding comments or using pseudocode or showing how you derived the function. State any assumptions you make.

2. (a) Write a function, printdivisors, that takes a single integer parameter and prints all the numbers less that the parameter that are divisors of the parameter (i.e. divides it without a remainder) including 1. So printdivisors(6) will print 1,2,3. Note you may use a wrapper function or default parameters.

(b) Write a function, sumdivisors, that takes a single integer parameter and returns the sum of all the divisors of the parameter (including 1). So sumdivisors(6) will return 6 as 1+2+3=6. Note you may use a wrapper function or default parameters.

(c) Write a function, allperfects, that takes two parameters, each an integer, in any order and prints out all the perfect numbers between the lower parameter and the higher parameter. A perfect number is one is which the sum of its divisors is equal to the number itself.

Remember to explain your functions, either by adding comments or showing how you derived the function. State any assumptions you make.

3. (a) Write a recursive function, printZeros, which prints out a series of zeros. The function takes one parameter and prints out the number of zeros specified by the parameter. So printZeros(4) will print: 0000 and printZeros(2) will print 00.

(b) Write a recursive function, printZPattern, which prints out a pattern of zeros as follows:

printZPattern(3) outputs:

printZPattern(1) outputs:

printZPattern(4) outputs:

000

0

0000

00

 

000

0

 

00

 

 

0

(c) How would you modify your second function to print a mirror pattern, such as (you do not have to code this one, just explain):

printZPattern2(3) outputs: 000
00
0
00
000

Remember to explain your functions, either by adding comments or showing how you derived the function. State any assumptions you make.
4. Suppose you have a function, myfib, declared as follows:

def myfib( n):

which returns the nth Fibonacci number, using this function:

(a) Write a function, myfibseries, that also takes a single parameter, n, and prints out the entire sequence of Fibonacci numbers up to and including n, with a comma between each (do NOT use loops).

(b) Write a function, myfibseriesR, that also takes a single parameter, n, and prints out the entire sequence of Fibonacci numbers up to and including n, with a comma between each, but in REVERSE order (do NOT use loops).

(c) Write a function, myfibsum, that takes a single parameter, n, and prints out the sum of all the Fibonacci numbers up to and including n (do NOT use loops).

5.

(a) Write a program that reads 10 numbers from the user as input and loads them into a list.

(b) Add a function search that takes one int parameter -n- and searches for all the occurrences of n in the list.

6. Guessing Game(max of 3 tries): Write a program to simulate the following guessing game using the random_in_range function :(Basically, the program should generate a secret number in the range the use specifies and it guides the user until she gets it right or exhausts 3 attempts.

The output of your program should be something like this:
Enter min of range
10
Enter max of range
20
Guess a number between 10 and 20 Guess a Number:
17
You went too low Guess a Number: 18
You got it!

Please do ONLY ONE of the following two options

Option I

In this question you are required to use Python to solve a problem of your choice. This could be a finance, accounting, science or any business, engineering or medical application. A game of your choice is ok too (no Graphical User interface would be required). If you are interested in writing a multi-user game, come see me and I will guide you or look up how sockets could be defined - there are many examples on the web. Of course, you can look up how to do things, but you need to use YOUR OWN CODE. Your program should include:

1- Classes (use hiding, getters and setters, multiple constructors and methods).

2- Use functions - make your main very short. Try not to use any long detailed logic in main and modularize your application.

3- Input and Output files.

4- Make your own data set. You can even use random functions to create data sets or use a data set that would be deemed appropriate for your application.

5- Use static variables in classes so that you would give an entity an auto-incremented ID as needed.

6- When using a data set, make sure you demonstrate your knowledge of sorting and searching (no need to prompt the user if you don't want to, but feel free to design your application as you deem appropriate).

7- For a very large extra credit, get a raspberry pi, configure it, and run the application on it. 8- You must use some containers (lists and/or maps).

9- You can use recursion if you know how and if you need it.

10- You may use any of the functions I have on BB in the code or from the book.

Come up with something cool or something useful. It does not have to be long but it must show what you learned in the course. Please make sure it is all yours from the idea to the implementation. I made this so open ended so that you gauge it to how much you want to do and you are able to do - but it MUST be yours - don't copy - it will not work. Come up with your own idea. Of course, no two ideas will come out similar, and if they do, the implementations will be completely different. Also, this must be something that has significance - as an idea and a prototype implementation. It can't be something trivial.

Option II

Write a 5-6 page paper (Preferred)) about ONE of the following topics (It must be in your own words):

1- Compare Python with Java, C++ and Ruby and how programming languages and tools are evolving (cloud, mobility, IoT, features, enhancements, complexity, performance, openness, etc), and when the use of one would be more appropriate than the others (if you such preference exists).

2- C++ 11 and C++ 14 features and enhancements - you must explain in your own words - don't copy. Do the research. How does this make C++ compared to Python, Java and Ruby? Do you think using boost libraries place C++ ahead of those languages when it comes to abstraction? Why is C++ is still so popular in some settings? What are those settings and when would you use it over any of the other languages above?

3- Advances in AI - Technical Perspective. What is new? What are the recent technical advances and challenges? How the technical landscape of Computational Sciences is well suited for yet another leap of advancements in Artificial Intelligence research and capabilities?

4- Functional Programming - with examples of how different modern languages support functional programming - with examples of your own.

5- The Internet of Things Development - You can discuss the different tools and platforms or you can discuss IoT applications in a specific domain (business, engineering or medical).

6- Cloud computing Development platforms (any of these topics: architecture, possibilities, scale, application - why it makes business sense, etc). You will need to discuss what services such as Azure, AWS or Bluemix offer and how this is revolutionizing software development. You can also approach this from an IaaS, PaaS, SaaS perspective but you need to discuss the stack of tools and the architecture along with some applications - possibly in a related domain (use of a business case scenario is perfectly fine).

7- Social Media Analytics - benefits, and what it means to business.

8- Big Data, Data Mining and Machine Learning - you could be general or use industry specific examples - but you need to discuss tools and architecture.

9- Any other topic - It must be related to programming, application development or specific technologies in a specific domain.

You must appropriately cite your sources in appropriate format. You can use IEEE format or LNCS format for your paper - or you can choose another format as you deem appropriate.

Python, Programming

  • Category:- Python
  • Reference No.:- M92358064

Have any Question?


Related Questions in Python

Part i the assignment filesone of the most important

Part I: The Assignment Files One of the most important outcomes of this assignment is that you understand the importance of testing. This assignment will follow an iterative development cycle. That means you will write a ...

Homework -this homework will have both a short written and

Homework - This homework will have, both a short written and coding assignment. The problems that are supposed to be written are clearly marked. 1) (Written) Make heuristics Describe two heuristics for the slide problem ...

Tasksdemonstrate data scraping of a social network of

Tasks Demonstrate data scraping of a social network of choice. Develop technical documentation, including the development of the code & detailing the results. Provide a report on the findings, that includes research into ...

Assignment1 utilising python 3 build the following

Assignment 1. Utilising Python 3 Build the following regression models: - Decision Tree - Gradient Boosted Tree - Linear regression 2. Select a dataset (other than the example dataset given in section 3) and apply the De ...

Python programming assignment -you first need an abstract

Python Programming Assignment - You first need an abstract base class, called, Account which has the following attributes and methods: accountID: This attribute holds the ID assigned the account , if not provided set to ...

Learning outcomes lo3 - research develop and document a

Learning Outcomes LO3 - Research, develop, and document a basic security policy, and analyse, record, and resolve all security incidents LO4 - Identify and assess the threats to, and vulnerabilities of networks Assessmen ...

Question research pythons dictionary data type dictdiscuss

Question : Research Python's dictionary data type (dict). Discuss its interface and usage. Include examples. Discuss practical applications of dictionaries.

Questionwhat is a python development frameworkgive 3

Question What is a python development framework? Give 3 examples python development framework used today. and explain which development framework is used in which industry.

Below zero - ice cream storethe local ice-cream store needs

Below Zero - ice cream store The local ice-cream store needs a new ordering system to improve customer service by streamlining the ordering process. The manager of the store has found that many orders are incorrect and s ...

The second task in this assignment is to create a python

The second task in this assignment is to create a Python program called pancakes.py that will determine the final order of a stack of pancakes after a series of flips.(PYTHON 3) Problem Task In this problem, your input w ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As