Repeat-2

A MathWikiből
(Változatok közti eltérés)
(Problem 3():)
(Problem 3(5 point):)
15. sor: 15. sor:
 
  increasing(1, 2, 1, 2, 1) -> False
 
  increasing(1, 2, 1, 2, 1) -> False
  
==Problem 3(5 point):==
+
==Problem 3 (5 point):==
 
Write a Vector class. It's parameter should be an arbitrary n dimensional vector. (A list of n real numbers.)
 
Write a Vector class. It's parameter should be an arbitrary n dimensional vector. (A list of n real numbers.)
  

A lap 2021. április 30., 08:05-kori változata

Problem 1 (2.5 point):

Write a search() function, which first parameter is an x and after that it can have arbitrary many named parameters. (search(x, **kwargs)) The function should return True, if there exist a key in kwargs, for which the corresponding value is x. Otherwise it should return False.

Examples:

search(2, a=1, b=3) -> False
search(2, a=1, b=3, c=2) -> True

Problem 2 (3.5 point):

Write a variadic increasing() function, which inputs are arbitrary many positive natural numbers, and it returns True if the sequence of the numbers contains an increasing subsequence of length 3.

Examples:

increasing(1, 2, 1, 2, 4) -> True
increasing(1, 2, 1, 2, 1) -> False

Problem 3 (5 point):

Write a Vector class. It's parameter should be an arbitrary n dimensional vector. (A list of n real numbers.)

a) Write the __init__ and __str__ methods!(0.5 point)

b) Write the __mul__ method which calculates the dot product of two vectors. (1.5 points)

c) Write the norm method which calculates the length of the vector. (1 points)

d) Write a test method which returns True if the angle between the vector and the x-axis is between 0 and 45 degrees. It might be useful to use the norm method and to import the math package.(2 points)

Example:

v1 = Vector([1, 2, 3])
v2 = Vector([1, 0, 1])
print(v1) -> [1, 2, 3]
print(v1*v2) -> 4
print(v2.norm()) -> 1.41
print(v1.test()) -> False
Személyes eszközök