Question

In: Computer Science

Using Python: Part 1: Write the following function in a file called listlab.py list4(): This function...

Using Python:

Part 1:

Write the following function in a file called listlab.py

list4(): This function takes four formal parameters. If all four inputs are of type int and/or float, return the largest of the four inputs. Otherwise, return a list containing the four input parameters. Remember the type() function from Chapter 2.2; you may also want to use max().

Notes:

  1. Every function must have a docstring, and variable names other than input parameters and loop control variables must have meaningful names. We will be grading for this.

  2. Do not put a call to your function at the bottom of the file.

Part 2:

Write a Python function `make_triangle(trianglechar, triangleheight) that will return a string with an isosceles right triangle based on the two formal parameters triangle_height giving the triangle height and triangle_char that gives the symbol to be printed.

Important notes:

  1. This program returns (not prints!) a string.
  2. For this function and the other part of this lab you are required to put in a docstring. That will be checked by a TA/grader reading the program.
  3. Every one of the occurrences of triangle_char should have a single space after it, including the ones at the ends of lines.
  4. This is not too complex to write either using while or using for and range(). If you're comfortable with for() and range(), that might be a little easier.
  5. The two ways we thought of to do this are either using two loops, one nested inside the other, or using one loop and string multiplication.
  6. `\n' is the newline character. Your returned string should have triangle_char of them. (One at the end of every "line".)

Solutions

Expert Solution

def list4(a, b, c, d):
        permittedtype = [int, float]
        if type(a) in permittedtype and type(b) in permittedtype and \
                type(c) in permittedtype and type(d) in permittedtype:
                return max(a, b, c, d)
        else:
                return [a, b, c, d]

def make_triangle(trianglechar, triangleheight):
        i = 1
        s = ''

        while i <= triangleheight:
                s += trianglechar * i + '\n'
                i += 1
        
        return s.strip()


**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Python 3.7.4 (default, Jul [GCC 6.3.0 20170516] on li def list4(a, b, c, d): 2 permittedtype [int, float] 3 if type(a) in permittedtype and type(b) in permittedtype and \ 4 ** type(c) in permittedtype and type(d) in permittedtype return max(a, b, c, d) 6 else: 7 return [a, b, c, d] CO def make_triangle(trianglechar, triangleheight) 10 i = 1 11 12 S = 13 while i = triangleheight 14 * i'\n' trianglechar 15 S i += 1 16 17 return s.strip() 18 19 print (make_triangle('*', 6)) 20 21


Related Solutions

Using Python 3 Write a function reads the file called simpleinterest.txt. Each row in simpleinterest.txt is...
Using Python 3 Write a function reads the file called simpleinterest.txt. Each row in simpleinterest.txt is a comma seperated list of values in the order of PV, FV, n, r. For each row, there is one value missing. Write an output file that fills in the missing value for each row.
Write a Python program in a file called consonants.py, to solve the following problem using a...
Write a Python program in a file called consonants.py, to solve the following problem using a nested loop. For each input word, replace each consonant in the word with a question mark (?). Your program should print the original word and a count of the number of consonants replaced. Assume that the number of words to be processed is not known, hence a sentinel value (maybe "zzz") should be used. Sample input/output: Please enter a word or zzz to quit:...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called main that does the following: Creates a directory called CyberSecurity-Notes in the current working directory Within the CyberSecurity-Notes directory, creates 24 sub-directories (sub-folders), called Week 1, Week 2, Week 3, and so on until up through Week 24 Within each week directory, create 3 sub-directories, called Day 1, Day 2, and Day 3 Bonus Challenge: Add a conditional statement to abort the script if...
Using Python 3 Write a program that reads the 4letterwords.txt file and outputs a file called...
Using Python 3 Write a program that reads the 4letterwords.txt file and outputs a file called 4letterwords.out that has every word found in 4letterwords.txt but each word on one line. Any leading and trailing blank spaces must be removed in the output file.
Part 1: Write a Python function called reduceWhitespace that is given a string line and returns...
Part 1: Write a Python function called reduceWhitespace that is given a string line and returns the line with all extra whitespace characters between the words removed. For example, ‘This line has extra space characters' 'This line has extra space characters’ • Function name: reduceWhitespace • Number of parameters: one string line • Return value: one string line The main file should handle the file operations to read from a .txt file you create and call the function from the...
Write a python program: There is a file called file 2. File2 is a txt file...
Write a python program: There is a file called file 2. File2 is a txt file and I have written the contents of file 2 below in the exact format it was in notepad. # This comment does not make sense # It is just to make it harder # The job description starts after this comment, notice that it has 4 lines. # This job description has 700150 hay system points\\ the incumbent will administer the spending of kindergarden...
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings....
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings. The first string is #the filename of a file to which to write (output_file), and #the second string is the filename of a file from which to read #(input_file). # #In the input file, there will be an integer on every line. #To the output file, you should write the integer from the #original file multiplied by the line number on which it #appeared....
Write the following Python script: Write a function called linsolve() that will be useful in categorizing...
Write the following Python script: Write a function called linsolve() that will be useful in categorizing and solving linear algebra problems. The function will have up to three parameters: • A required 2D array representing the coefficient matrix of a linear algebra equation, • A required 1D or 2D array representing the right-side constants of a linear algebra equations, and • An optional parameter used to determine which condition number to use in determining the condition of the system. The...
In python please write the following code the problem. Write a function called play_round that simulates...
In python please write the following code the problem. Write a function called play_round that simulates two people drawing cards and comparing their values. High card wins. In the case of a tie, draw more cards. Repeat until someone wins the round. The function has two parameters: the name of player 1 and the name of player 2. It returns a string with format '<winning player name> wins!'. For instance, if the winning player is named Rocket, return 'Rocket wins!'.
#Python 5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified:...
#Python 5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified: Request input from the user for three variables (floating-point or integer) x, y, z, and myAverage. If the average of the first three numbers equals the fourth number, print 'Your average is correct.'. If not print 'Your average is not correct'. and print the correct average. Print the largest value among x, y, and z. Print the minimum value of x, y, y. >>>...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT