Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks
Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.
Note: Please read the comments attached very carefully, because there could be different variations of the method (especially pythagorian_coprimes) according to different translations of the question, and if the code I attached did not perform what you expect it to perform, let me know first, I’ll update the code quickly.
#code
# problem 4
def pythagorian_coprimes(n=100):
for a in range(2, n):
for b in range(2, a):
c = (a * a + b * b) ** 0.5
if c > n:
break
if c == round(c):
# storing values of a and b in two variables, to find gcd
# note: if you are allowed to use math library, you can
# just simply call gcd=math.gcd(a,b) and remove below 5 lines (not comments)
x = a
y = b
# looping until y is 0
while y > 0:
# using euclidian algorithm to find gcd of x and y
x, y = y, x % y
# at the end, value of x will be the gcd
gcd = x
# checking if gcd is 1
if gcd == 1:
# printing a and b. if you want to yield values instead, change print to yield
# you may also include c if you want, but the question demands "prints all pairs
# of positive integer numbers (a,b)" which is why I wrote the below line.
print (a, b)
# problem 5
def acronym(string):
# creating an empty string
s = ''
# looping through each word in string
for word in string.split():
# converting first letter to upper case and appending to s
s += word[0].upper()
# returning s
return s
# testing problem4
# note: if you used yield instead of print inside pythagorian_coprimes, you will need to use a loop
# like -> for a,b in pythagorian_coprimes(): print(a,b)
pythagorian_coprimes()
# similarly call acronym method with test input if you want to.
#code screenshot

#output

PLEASE HELP! python code Problem 4. Define the function pythagorian_coprimes (n=100) that prints all pairs of...
Define the functions in Python 3.8
1. Write a function most frequent n that takes a list of strings and an integer n, and that returns a dictionary where the keys are the top n most frequent unique words in the list, and the values are the frequency of each word: For example, most frequent n(text, 3) should return the dictionary {'is': 2, "the’: 3, 'of': 2}, and most frequent n(text, 2) could return either {'is': 2, 'the’: 3} or...
please use python to solve
Problem 4 (a) Write a function is_sum_squares (n) that returns True if n can be written as a² + b2 , where a, b are integers, and False otherwise. For example is_sum_squares (5) is True since 5 = 12 + 22, while is_sum_squares (3) is False. (b) Compute is_sum_squares (7), is_sum_squares (11), is_sum_squares (13), is_sum_squares(17), is_sum_squares (19), is_sum_squares (23). (c) What is the pattern for is_sum_squares(p) when p is prime. (HINT: look at p %...
Please write a code in python! Define and test a function named posterize. This function expects an image and a tuple of RGB values as arguments. The function modifies the image like the blackAndWhite function, but it uses the given RGB values instead of black. images.py import tkinter import os, os.path tk = tkinter _root = None class ImageView(tk.Canvas): def __init__(self, image, title = "New Image", autoflush=False): master = tk.Toplevel(_root) master.protocol("WM_DELETE_WINDOW", self.close) tk.Canvas.__init__(self, master, width = image.getWidth(), height = image.getHeight())...
i
need the solution in pseudo code please.
4 Dynamic Programmii Consider the following problem based on the transformation of a sequence (or collection) of coloured disks. Assume that you have a very large collection of disks, each with an integer value representing the disk colour from the range [0, cl. For example, the colour mapping might be: O-red, 1-yellow, 2-blue, 3-pink,. c-black For a given sequence of coloured disks eg.,0,1,2,3,4), at each time step (or iteration) you are only...
Python, given a code in class i just need help with the third
bullet point ; using a and n (defined in the second picture of
python code) find the first digit for k! for k =1,...,n. you dont
have to type in all this code just help me write the code in the
first picture where it says: def benford(a):
b = [0 for d in range(1,10)]
#Do everthything in here
return b
2.2 Generating data In this assignment...
Please write the complete code in C. Write a C function that prints the minimum spanning tree of a graph. At the end, print the weight of the spanning tree. A suggested report format is shown in the following example. Source Vertex To Vertex Weight A B 2 A C 4 B D 3 D E 1 Total weight of spanning tree: 10 Your main program will read a graph from DataIn file to an adjacency table before calling the...
please help! SHOW ALL WORK
Can someone explain why for part b when I solve for
the wavelength instead of 0.28 i get 2.81(im doing 2pi/k and have
no clue why the answer is 0.28)
Name Problem 4 Two waves, one with wave function D0.250 sin(2.27x 16.71), and another with wave function D2 = 0.250 sin(2.27x + 16.70, interfere to form a wave with displacement D = Di D2-Note that aff values are in SI (mks) units and angles are...
Hello can anyone help solve this please in Python the way it's
asked?
Question 22 40 pts List Comprehensions Write the solution to a file named p2.py and upload it here. Comprehensions will show up at the midterm exam, so it's important to practice. a) Write a list comprehension that returns a list [0, 1,4, 9, 16, .. 625] starting from range(0, 26). (lots of list elements were omitted in ...) b) Write a list comprehension that returns the list...
please help answer these
QUESTION 4 Which managerial function involves setting goals, establishing a strategy to pursue those goals, and forecasting future threats and opporturites hat might influence the company's needs and strategies? O A planning С.leading ○D.cortrolig QUESTIONS What term reders to the fit between an individual's values, beliefs, attitudes, and personality and the values, norms, and cuiture of the organization? OA person-organization f ○B.person+ob fit O C.person-vocation ft OD.person-group fit QUESTION 6 What term refers to the fit...
Can someone please help me fix my code on this assignment that's due in the morning? Please read the question carefully. Using C++, construct a graph class, graph.template, in which the edges are stored in adjacency sets. You need to use graph.h and test_graph.cpp to implement graph.template. The author provides an implementation of a graph using an adjacency matrix. I have started the template file but I cannot get it to compile. I have posted my template file of what...