Python Forum
Python OOP - two numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python OOP - two numbers
#11
seven_boom_range does not need to have the parameters small & big
def seven_boom_range(self):
it can access them as self.small and self.big, then it is making use of the attributes and would not work as a standalone function.
ben1122 likes this post
Reply
#12
(Sep-30-2021, 06:51 PM)Yoriz Wrote: seven_boom_range does not need to have the parameters small & big
def seven_boom_range(self):
it can access them as self.small and self.big, then it is making use of the attributes and would not work as a standalone function.

Oh I see what you mean:
    def seven_boom_range(self):
        empty = []
        if self.big > self.small:
            self.small, self.big = self.big, self.small
        if self.small > self.big:
            for i in range(1, self.small - self.big + 1):
                if "7" in str(i) or i % 7 == 0:
                    empty.append("BOOM")
                else:
                    empty.append(i)
            empty.insert(0, 0)
        return empty
So if I do it outside of class it would not work.
that way its good right?

about the function though, for seven boom, its probably the best method I can get right?
Reply
#13
It's your homework if that's the best you can do, sure, that's the best you can do.
if you correct your logic you can get rid of
if self.big > self.small:
        self.small, self.big = self.big, self.small
because that is already done in the __init__
Reply
#14
I thought of it before, but sadly the list wont work that way.
I will try it ( although I tried before ).
Update if I success.
Thanks :)
Oh. I actually tried something, you are right, is that good? or bad?
    def seven_boom_range(self):
        empty = []
        for i in range(1, abs(self.small - self.big - 1)):
            if "7" in str(i) or i % 7 == 0:
                empty.append("BOOM")
            else:
                empty.append(i)
        empty.insert(0, 0)
        return empty
I used abs function, although I think its not allowed for me to use it lol... I will try another way of doing it without doing abs, I know its something on the range, problem is it can be minus so I dont know how to reverse it... Ill try.
Reply
#15
What is the reasoning behind going from range 1 to big - small + 1
Is it maybe just supposed to go from the small number to the big number?
check your teacher's requirements.
Reply
#16
(Sep-30-2021, 07:07 PM)Yoriz Wrote: It's your homework if that's the best you can do, sure, that's the best you can do.
if you correct your logic you can get rid of
if self.big > self.small:
        self.small, self.big = self.big, self.small
because that is already done in the __init__

    def seven_boom_range(self):
        empty = []
        for i in range(1, self.big - self.small + 1):
            if "7" in str(i) or i % 7 == 0:
                empty.append("BOOM")
            else:
                empty.append(i)
        empty.insert(0, 0)
        return empty
Actually, managed again to do it, now without abs.
is that what you meant? I really hope so.. took me a few try and experience
(Sep-30-2021, 07:14 PM)Yoriz Wrote: What is the reasoning behind going from range 1 to big - small + 1
Is it maybe just supposed to go from the small number to the big number?
check your teacher's requirements.

There aint any teacher requirements.
All I wrote in the post ( about the questions, 1 2 3 4 ) is the quote he gave us for the question.
I quoted exactly from my laungage ( hebrew ) and translated myself to english, the exact words with same meaning.

And about the first range, because if I put 0, ill get zero division which is false.
so I start from 1.
about the +1, because otherwise I will reach 0 to 9.
lets say I put big 30, small 20
I will get a list of 0 to 9, but not 10, thats why I add +1.
Reply
#17
(Sep-27-2021, 05:35 PM)ben1122 Wrote: 4. print the difference between two numbers by seven boom.

requirement No.4 that is/is not a teacher requirement doesn't say go from zero to the big number - the small number?
it seems to read as between the two numbers.
Reply
#18
You didnt understand what I mean.
There arent any special requirements other then that:
""""
Write a class named: TwoNumbers

attributes:
first number - small
second number - big

methodes:
1. print in this format: small - (something), big - (something )
for example: small - 3, big - 9

2. a constructor which receives two numbers and reset the attributes of both of them ( no know the order of numbers )

3.GCD of both the numbers ( EDIT: forgot to mention, recursively )

4. print the difference between two numbers by seven boom.
"""
Only those are the requirements. nothing else written, same words, just translated from hebrew to english.
Now, it does say to go from small to big, It says to go to the range of the difference between the two.
If big - 40, small - 30, the difference between them is 10 right? so it does seven boom from zero to ten ( 0 to 10 ), thats the meaning.
Reply
#19
Yes you are correct I do not understand the requirements of your homework, it must be getting lost in the translation.
Reply
#20
(Sep-30-2021, 07:59 PM)Yoriz Wrote: Yes you are correct I do not understand the requirements of your homework, it must be getting lost in the translation.

uh... Its not lost in the translation. If you want, I will quote the question in hebrew and you can put it at google translate... its the same words, I know.
the question itself is not clear... its not new to me, I posted it before on stackoverflow because I didnt understand myself
look here:
https://stackoverflow.com/questions/6934...7_69345591

here is the translation from google translate, maybe it will help you understand:
Characteristics:
1. First number (small)
2. Number two (large)
Methods:
1. Print in the following format (for example for an object in which the smallest is about 7 and the largest about 19):
Small-7, Big-19.
2. A constructor that receives two numbers, and initializes both properties (it is not possible to know the order of the numbers).
3. Gcd - an action that returns the largest common divisor of the two numbers
Print7boom - An action that prints the range between the two numbers in the form of a 7 boom.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Generator: From Word to Numbers, from Numbers to n possibles Words Yamiyozx 2 1,427 Jan-02-2023, 05:08 PM
Last Post: deanhystad
  Convert list of numbers to string of numbers kam_uk 5 3,016 Nov-21-2020, 03:10 PM
Last Post: deanhystad
  Regular Expressions in Files (find all phone numbers and credit card numbers) Amirsalar 2 4,111 Dec-05-2017, 09:48 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020