Please code in Python:
A function can be assigned to a variable and passed into another function as an argument. Consider the following function that executes a function twice:
def exec_2(f): f() f()
any function that is passed into exec_2() will be executed twice without parameters. Your task is to write a function exec_4(f) that takes in a function f as a parameter and executes the function f 4 times using the function exec_2. The function f in this case will draw a cute koala bear, and, in conjunction with, exec_4(), you will draw 4 koalas on the same tree! Suppress the newline in the print statement for the koala, this can be done using print's end argument.
Default template code:
koala = """
| : .
|
| ' : ' |
| . | ' | |
.--._ _...:.._ _.--. , ' |
( , ` ` , ) .
|
'-/
\-' | |
| o /\ o
| :|
\
_\/_ / : ' |
/'._ ^^
_.;___ |
/`
`""""""` `\= |
/`
/= .|
;
'--,-----'= |
|
`\ | . |
\
\___ : |
/'.
`\= |
\_/`--......_
/= |
|`-. /= : |
| : `-.__ /` . |
| . ` | '|
| . : ` . | |"""
def exec_2(f):
f()
f()
def exec_4(f):
# define this function using exec_2
# define a new function here that prints out the koala once
# use your function and exec_4 to draw 4 koala bears!
Here is the python code to print 4 koala bears by calling the functions.
There are sufficient comments in the code for you to understand.
Note: You may look the screenshot of the code to have better understanding of the indentation.
Python code:
#function to print koala bear once
def f():
koala = """
| : . |
| ' : ' |
| . | ' | |
.--._ _...:.._ _.--. , ' |
( , ` ` , ) . |
'-/ \-' | |
| o /\ o | :|
\ _\/_ / : ' |
/'._ ^^ _.;___ |
/` `""""""` `\= |
/` /= .|
; '--,-----'= |
| `\ | . |
\ \___ : |
/'. `\= |
\_/`--......_ /= |
|`-. /= : |
| : `-.__ /` . |
| . ` | '|
| . : ` . | |"""
#print koala variable
print(koala, end='')
#function to print twice koala
def exec_2():
#call function f() twice
f()
f()
#function to print koala 4 times
def exec_4():
#call function exec_2() twice
exec_2()
exec_2()
#call function exec_4() to print bear 4 times
exec_4()
Output:
Please code in Python: A function can be assigned to a variable and passed into another...
Basic Python code needed Define the get_lines_from_file) function which is passed a filename as a parameter. The function reads the information from the file (corresponding to the filename parameter) and returns a list of strings where each element of the returned list corresponds to one line of the file. The list of strings which is returned by the function should not contain any newline characters. For example, if the file contains the text: 10 440 240 4 42 4 42...
# 1111111111111111111111111111111111111111111111111 # draw_histogram() #-------------------------------------------------- #-------------------------------------------------- """ Define the draw_histogram() function which is passed a Python dictionary as a parameter. The keys of the dictionary are single letters and the corresponding values are integers, e.g., {'b': 5, 'a': 6, 'c': 3}. For each key:value pair in the dictionary the function prints the key, followed by ": ", followed by a series of stars. The number of stars printed is given by the value corresponding to the key. The keys are...
In C please Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original maino: int main(void) { double milesPerHour, double minutes Traveled; double hours Traveled; double miles Traveled; scanf("%f", &milesPerHour); scanf("%lf", &minutes Traveled); hours Traveled = minutes Traveled / 60.0; miles Traveled = hours Traveled * milesPerHour; printf("Miles: %1f\n", miles Traveled); return 0; 1 #include <stdio.h> 3/* Your solution goes here */ 1 test passed 4 All tests passed...
c++ please include comments 4. Rewrite the code below including the definitions of the function prototypes #include <iostream> #include <iomanip> #include <string> #include <stream> using namespace stod bool disjunction(bool.bool) bool negation(bool): bool implication(bool,bool bool equi bool,bool char btoc(bool value) return (value)?(T") ('F); string truthTable); int main( cout << truth Ta return 0; The functions conjunction), disjunction), negation), implication), and equivalence) should return the truth value of the conjunction, disjunction, negation, implication and equivalence connectives respectively. The functions truthTable) return a...
Python 2.7.14 Programming Assignment Shape Drawing With Notepad++(PLEASE READ AND FOLLOW THESE INSTRUCTIONS THOROUGLY AS THIS ASSIGNMENT IS FOR PYTHON 2.7.14. ONLY AND I REALLY NEED THIS TO WORK!!! ALSO PLEASE HAVE THE CODE PROPERLY INDENTED, WITH WHATEVER VARIABLES DEFINED, WHATEVER IT TAKES TO WORK FOR PYTHON 2.7.14. I feel like nothing I do is working and I'm trying everything I can think of. ): In this assignment, the student will create a Python script that implements a series of...
python 2..fundamentals of python 1.Package Newton’s method for approximating square roots (Case Study 3.6) in a function named newton. This function expects the input number as an argument and returns the estimate of its square root. The script should also include a main function that allows the user to compute square roots of inputs until she presses the enter/return key. 2.Convert Newton’s method for approximating square roots in Project 1 to a recursive function named newton. (Hint: The estimate of...
can someone please help me write a python code for this urgently, asap Question: Write a Python function, minmp, that is passed a file name and a metal alloy's formula unit structure*". The file will contain metal elements and their properties. The function will return a tuple of the element from the formula with the lowest melting point and that melting point Write a second function, molform, that will be called by the first function, to take the metal alloy's...
PLEASE HELP! python code Problem 4. Define the function pythagorian_coprimes (n=100) that prints all pairs of positive integer numbers (a, b) such that c = a + b is also a whole number and 1 <c<n. Include only those triples that are co-prime (do not have any common divisors other than 1). For example, (3, 4, 5) is okay but (30, 40, 50) should be skipped. Help: As a starting example, examine the function pythagorian_triples that yields all triples. Modify...
IT PYTHON QUESTION1 Consider the following Python code, where infile.txt and outfile.txt both exist in the current directory 'z' ) 。1d = open ( ' infile. txt ' , for line in old: new.write (line) new.write') ne«.close () old.close) Which of the following options best describes the purpose or outcome of this code? O A copy of the file infile.txt is made (except in double line spacing) and saved as outfile.txt in the current directory. O A copy of the...
Please answer this question using python programming only and provide a screen short for this code. Homework 3 - Multiples not less than a number Question 1 (out of 3) This homework is a SOLO assignment. While generally I encourage you to help one another to learn the material, you may only submit code that you have composed and that you understand. Use this template to write a Python 3 program that calculates the nearest multiple of a number that...