Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

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

Question a software company sells a package that retails

Question : A software company sells a package that retails for $99. Quantity discounts are given according to the following table: Quantity Discount 10 - 19 20% 20 - 49 30% 50 - 99 40% 100 or more 50% Write a program usi ...

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

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.

Lab assignment -background - we have discussed in detail

Lab Assignment - Background - We have discussed, in detail, the function of Stacks and Queues and how they are specifically implemented in Python. To get a better understanding of the utility of these data structures, we ...

Question why is software configuration management

Question : Why is software configuration management considered an umbrella activity in software engineering? Please include examples and supporting discussion. The response must be typed, single spaced, must be in times ...

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

Architecture and system integrationcase study queensland

Architecture and System Integration Case Study: Queensland Health - eHealth Investment Strategy After evaluating various platforms, Queensland Health finally decided to adopt a Service Oriented Architecture (SOA) for its ...

Quesiton write a python script that counts occurrences of

Quesiton: Write a python script that counts occurrences of words in a file. • The script expects two command-line arguments: the name of an input file and a threshold (an integer). Here is an example of how to run the sc ...

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

Simple python traffic lightswrite a program that simulates

Simple Python (Traffic lights) Write a program that simulates a traffic light. The program lets the user select one of three lights: red, yellow, or green. When a radio button is selected, the light is turned on, and onl ...

  • 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