Write a recursive function that takes in a list

Assignment Help Python Programming
Reference no: EM131041575

Homework 8 - Recursion

Assignment: Homework 8 - Recursion

Homework 8 is designed to help you practice using recursion to solve problems. (Remember, a recursive function must have at least one base case and at least one recursive case!)

Remember to enable Python 3 before you run your programs:

/usr/bin/scl enable python33 bash

Instructions

Each one of these exercises should be completed in a separate python file. For this assignment, you may assume that all the input you get will be of the correct type (e.g., if you ask the user for a whole number, they will give you an integer).

For this assignment, you'll need to follow the class coding standards, a set of rules designed to make your code clear and readable. The class coding standards are on Blackboard under "Course Documents" in a file titled "CMSC 201 - Python Coding Standards."

You should be commenting your code, and using constants in your code (not magic numbers or strings). You should also have a function header comment for every function that is not main()!

Re-read the coding standards!

You will lose major points if you do not following the 201 coding standards.

A very important piece of following the coding standards is writing a complete file header comment block. Make sure that each file has a comment block at the top (see the coding standards document for an example).

NOTE: You must use main() in each of your files.

Details

Homework 8 is broken up into three parts. Make sure to complete all 3 parts.

Each part must use a recursive function to solve the given problem.

NOTE: Your filenames for this homework must match the given ones exactly. And remember, filenames are case sensitive.

hw8_part1.py

For this part of the homework, you will write a recursive function that takes in a list of positive integers as a parameter, and prints out the maximum value in that list. Your recursive function should be called maxInt().

The list of positive integers should be obtained by prompting the user to enter numbers, allowing them to use "-1" to stop adding integers to the list.

You may NOT use the max() function to calculate the maximum.

Here is some sample output for hw8_part1.py, with the user input in blue. Your output does not need to be identical, but should be similar.

bash-4.1$ python hw8_part1.py Enter a number to append to the list, or -1 to stop: 15 Enter a number to append to the list, or -1 to stop: 20 Enter a number to append to the list, or -1 to stop: 13 Enter a number to append to the list, or -1 to stop: 30 Enter a number to append to the list, or -1 to stop: 22 Enter a number to append to the list, or -1 to stop: -1 The list you entered is: [15, 20, 13, 30, 22] The maximum value in the list is: 30

hw8_part2.py

For this part of the homework, you will write a recursive function that prints a hollow square. Your recursive function should be called hollowSquare(), and must take in three arguments: an integer for the square height, the character the user has chosen to "draw" the square with, and a counter variable to keep track of "where" you are when drawing the square.

Your program should prompt the user for these inputs, in exactly this order:

1. The height of their square

2. The symbol the square will be made of

You cannot assume that the provided height will be a valid value! The user will always provide an integer, but you must perform basic input validation to ensure that the height you accept is greater than or equal to 1.

Remember to prompt the user with what you will accept as valid input. (Don't just tell them their choice is incorrect; tell them what the acceptable values are as well.)

Here is some sample output, with the user input in blue.

bash-4.1$ python hw8_part2.py Please enter the height of your square: -3 Please enter the height of your square (must be > 0): 0 Please enter the height of your square (must be > 0): 10 Please enter a character for your square: # ########## # # # # # # # # # # # # # # # # ##########

(Because characters are taller than they are wide, your "square" won't appear to be square - this is fine!)

hw8_part3.py

Finally, you will be given an input file, from which you will build a list of all unique characters in that file, using a recursive function.

Your recursive function should be called newChar()and should take in at least two parameters: the string from the file and a list to store all of the unique characters.

You will not be asking the user for the name of an input file. It will always be named input.txt, and should be able to contain any type of text.

Your program should print out the list of all unique characters. (Hint: you can achieve this by using print(listNameGoesHere) in your code.)

Here is the sample output for hw8_part3.py.

bash-4.1$ python hw8_part3.py ['T', 'h', 'e', ' ', 'q', 'u', 'i', 'c', 'k', 'b', 'r', 'o', 'w', 'n', 'f', 'x', 'j', 'm', 'p', 'd', 'v', 't', 'l', 'a', 'z', 'y', 'g', "'", 's', '.', '\n', '"', 'F']

Here is text in the input.txt file used to create the above sample output:

The quick brown fox jumped over the lazy dog's tail. "For realz."

Reference no: EM131041575

Questions Cloud

Global perspectives on indigenous peoples : This assignment is an opportunity for you to reflect on the material we have covered this semester, but you must take the final module, "Global Perspectives on Indigenous Peoples," into careful consideration.
Improve business operations by changing communication system : In this third assignment you now need to address how these two organisations can improve business operations by changing their communication systems and network elements and by adopting new network technologies and/or improvements to management th..
How css is used to create the layout for a web page : Describe in detail how JavaScript can be used for input validation on the client side. Explain in detail how CSS is used to create the layout for a web page.
Equipment after-tax salvage value : What is the equipment's after-tax salvage value for use in a capital budgeting analysis? Note that if the equipment's final market value is less than its book value, the firm will receive a tax credit as a result of the sale.
Write a recursive function that takes in a list : For this part of the homework, you will write a recursive function that takes in a list of positive integers as a parameter, and prints out the maximum value in that list. Your recursive function should be called maxInt().
Prepare journal entries for walkie ltd : Determine the balance of any current and deferred tax assets and liabilities as at 30 June 2015, in accordance with AASB 112 - Prepare journal entries for Walkie Ltd between 1 July 2013 and 1 January 2017to record the above. Show narrations and al..
Develop a web site to support the mrsl : Most simply put, you will develop a web site to support the Murfreesboro Recreational Soccer League (MRSL) operation. You will build this web using HTML 5, CSS 3, Tables, Images and Forms
Do you think same sex marriage should be legal : The US Supreme Court has ruled that same sex marriage is legal nationwide since June 6, 2015. However, the new law does not stop the battles of gay marriage across America. Do you think same sex marriage should be legal? Please state your own posi..
The social movement of time and place : This week we're reading across disciplines: history, philosophy, music, art, Europe, America, Asia...welcome to the Humanities. Hence our discussion will focus on influences. How does history, the social movement of time and place, influence art?

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