Write a function digitize that takes two parameters

Assignment Help Python Programming
Reference no: EM131549344

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.

Reference no: EM131549344

Questions Cloud

Explanation of the process associated : Provide a detailed explanation of the process associated with passing values by value and by reference. Following your description of this process
Impose the types of control necessary for a true experiment : In an ideal world, every research study would include strict experimental controls, randomization that perfectly mimics the population of interest.
The purpose of justice for a prosecutor to consider facts : Within juvenile justice, the prosecutors have broad discretionary powers pertaining to which cases are brought before a court for formal adjudication.
Roles of core technologies in an effective it system : A short paper describing the roles and significance of each of the five core technologies in the overall system. Discuss their relationships and interdependence
Write a function digitize that takes two parameters : Write a function digitize (using loops) that takes two parameters: one integer parameter and one bool parameter.
Discuss the field of education or leadership : What are the primary factors that make it more challenging to conduct experimental studies in the field of education or leadership?
Perceptron without a step or sigmoid threshold : As mentioned in class, a perceptron without a step or sigmoid threshold is simply a linear function, and therefore the learning is the same as linear regression
Class mean as simple euclidean distance : K-means (in its common simple form) implicitly assumes that all dimensions are comparable, since it measures distance of a sample to each class mean as simple
How issues of inequity were addressed or not addressed : Critically analysing the Project Piaxtla from a participatory planning approach to health and development: A reflection in Werner and Sanders.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd