Informatics2-2021/Lab09
(Új oldal, tartalma: „Home =Exercise= ==Palindrome== Write a function, called Palindrome, with one parameter which is a string. The function should check whether the s…”) |
|||
1. sor: | 1. sor: | ||
[[Informatics2-2021|Home]] | [[Informatics2-2021|Home]] | ||
=Exercise= | =Exercise= | ||
− | |||
− | |||
− | |||
− | |||
− | |||
== range == | == range == | ||
39. sor: | 34. sor: | ||
((x-1)/2)^2 + ((y-2)/3)^2 = 1 | ((x-1)/2)^2 + ((y-2)/3)^2 = 1 | ||
+ | |||
+ | ==Palindrome== | ||
+ | Write a function, called Palindrome, with one parameter which is a string. The function should check whether the string is a palindrome or not. The function should return "True" if the string is a palindrome, otherwise It returns "False". | ||
+ | |||
+ | ==Mersenne Prime== | ||
+ | Write a function, called Mersenne, with one parameter which is an integer. The function should check whether the number is a Mersenne Prime or not. The function should return "True" if the number is a Mersenne prime number, otherwise It returns "False". |
A lap 2021. április 14., 00:03-kori változata
Tartalomjegyzék |
Exercise
range
Write an iterable class like range, but without returning a whole list, but storing only the actual element.
class Range: def __init__( ... ): ... def __iter__( ... ): ... def __next__( ... ): ...
- Its constructor should have one parameter: a number or a string. The iteration should go up that number, from 0 with 1 steps.
- If the number is not positive, then the iteration should take 0 steps.
- If you get a string then try to convert it to a number. It it cannot be converted, then raise a ValueError exception.
- If it is a valid integer, then calculate with that.
- If you get the string "inf" then make the iteration go endless (infinite loop)!
Shapes
Write a class called Shape.
- Let it have two members: x and y, the coordinates of the shape on the plane (center of mass).
- Define a move method, with one parameter v: a list of length 2, a vector to translate the shape with. After this method the coordinates should be changed.
Define the following classes as children of Shape:
- Ellipse with additional parameters (except the (x, y) coordinates): a and b the x and y axes radii
- Rectangle with additional parameters (except the (x, y) coordinates) a and b the length of the sides
Write an area method for both, which calculates the area!
Define an equation method for printing the equation of the Ellipse! Something like:
((x-1)/2)^2 + ((y-2)/3)^2 = 1
Palindrome
Write a function, called Palindrome, with one parameter which is a string. The function should check whether the string is a palindrome or not. The function should return "True" if the string is a palindrome, otherwise It returns "False".
Mersenne Prime
Write a function, called Mersenne, with one parameter which is an integer. The function should check whether the number is a Mersenne Prime or not. The function should return "True" if the number is a Mersenne prime number, otherwise It returns "False".