Ask Python Expert

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."

Python, Programming

  • Category:- Python
  • Reference No.:- M91766025
  • Price:- $30

Priced at Now at $30, Verified Solution

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