#python help plz
1 messages · Page 1 of 1 (latest)
fuck python
but i sent you a video that explains it
indeed
im watching it
hmm I need to go, mom is yelling at me to do shit .-. but im in the middle of trying to solve this
this is only 1 /3 questions
question 2 is scary
using python for OOP
do you only have python on your github or smth
i mean you can ask to confirm this is the right things. like The document you sent me only references python. Is this correct as I applied for a position referencing Java and C#
not like people never make mistakes
also... how do I make classes in python? this seems strange
like interfaces and whatnot
ive never made interface in python before
you dont

theres no interface in python
at this step latest i would ask if python was the right lang
only classes. but you can treat them as abstract classes
apparently
from abc import abstractmethod, ABCMeta
so AbstractBase Class is an Interface
I hate python
you hate it because you dont understand it :p
it does oop just fine
but how if you cant make interfaces
why do you need an interface
Q2 needs ones .-..
ABC
im triyng to solve Q1 first though
im getting an error that copy is not defined
code
import copy
# Original object
document = [[1, 2, 3], [4, 5, 6]]
# Shallow copy
copy1 = copy.copy(document)
copy1[1][2] = 15
print("name=Original list= ", document)
print("name=Copy 1 list= ", copy1)
# Another shallow copy
copy2 = copy.copy(document)
copy2[0][2] = 3
print("name=Original list= ", document)
print("name=Copy 2 list= ", copy2)
# Deep copy
copy3 = copy.deepcopy(document)
copy3[1][0] = '456'
copy3[1][1] = 7
copy3[1][2] = 15
copy3[1][3] = 16
print("name=Original list= ", document)
print("name=Copy 3 list= ", copy3)
# Another deep copy
copy4 = copy.deepcopy(document)
copy4[1][0] = '789'
print("name=Original list= ", document)
print("name=Copy 4 list= ", copy4)
i asked AI for this to see what it came up with
whats the error
still have no idea why you do a non change on copy2
that AI did that, imma change it one sec
oh now I have list assignment out of range on line 23, which is copy3[][] = 16
yep makes sense
just so its in here
still not sure what to put in the document for the detailed explaination they want
explaining why the changes happened as they did
since you only ever edit the copies
copy makes a copy of the list, and it effects the original if you change the copy
deepcopy makes a copy of the list as a new object and therefor does not effect the original
thats the wwhole explaination
so just explain that detailed
[screenshot of copy1 vs original]
since we did X and its a Y the change on ZZZ results in the original also changing
its not bullshiterry
its showing you understand why the output is what it is
so 1 and 3 are shallow copies...
yes
id just explain the question in the word document show the example output, make up a new original list in your code, make up new changes (all after you know it does what it should), post the code and output as screenshots, then explain the code detailed so this is the original list as we can see its a list of lists being XYZ originally, next screenshot of cop1 vs original this is after we did the first copy being a shallow copy and editing these and those indexes with these and those numbers. as you can see it also changes the subentries of the list as its a shallow copy blablablabla
ofc write it nicely
Im guessing "Clone an object call document" is a typo?
yeh
theres more typos
seems the recruiter is indian so that makes sense
doesnt explain code typos lol
LOL
unless its an actually empty entry
I wouldnt doubt that
but yeah wouldnt matter since the same line has a change that makes it a deep copy
python.poggers
ban me, tickets dont get answered 
because the question says so
oh, I need to modify copy1 before printing it
traling commas are fine
yes
thats not a word document
yeh I know but I need to make the code first
also id just name them copy1 - copy4 as the question asks
maybe I should
if you want to be really cool you can assert yuor expectations :p
oh
insert image of you t-posing to assert your expectations
LOL
need to figure out how to insert a string into a specific index of a loosely typed list .-.
nah...I like knowing what type my data is at all times
Having the interpreter intepret it based on assumptions is not nice LOL
well, it works most of the time I guess
everything in python has a type, and its well defined
use [0] instead of [1]?
i assume youre rubberducking ebcause you done provide us with a proper question
shallowCopy2 = copy.copy(document)
shallowCopy2[1].insert(0, '456')
shallowCopy2[1][1] = 7
shallowCopy2[1][2] = 15
shallowCopy2[1][3] = 16
print("Shallow Copy 2:", shallowCopy2)
print("Original List: ", document, "\n")
that is incomplete
looks complete to me
what is document.
what is the output
what output is expected
how did that sticker get there
Well
I still need copy 4 xf
Ugh, question 2 now
Nothing for over an hour, so must be going well
I am writing the document for q1
And procrastinating slightly cause I'm scared of q3
Did they give an time estimate for the questions?
Well it's good excersice
Create a custom class called Value that will hold a number. Then add decorators that allow addition (Add) and subtraction (Sub) to a number (Value). The Add and Sub decorators can accept integers directly, a custom Value object or other Add and Sub decorators. Add, Sub and Value all implement the IValue interface and can be used recursively
what does it mean by "Can be used recursively"?
this is a weird exercice.
Yep
sure, a class with a value. sure.
a decorator.. is not an easy thing, but quite interesting technique.
does it say how to use the decorators?
because decorators themselves are applied to functions/classes
nope
this is the UML he gave with that descrition
idk how to use Decorators
I got my code to work but Add() and Sub() are not using Decorators AFAIK
decorators are fun. I found them hard to understand at first, but its is fairly simple.
a decorator does something with calling a function. before, after or both
so it can change the input of the function, or alter the output.
or just log for example
i have no idea what they mean with a decorator
chatgpt does something i would not call a decorator hehe
this is the code phind gave me when I asked it a bunch of questions about the code I wrote already
from abc import ABC, abstractmethod
class IValue(ABC):
@abstractmethod
def __int__(self):
pass
@abstractmethod
def __add__(self, other):
pass
@abstractmethod
def __sub__(self, other):
pass
def add_decorator(func):
def wrapper(self, other):
result = func(self, other)
return Add(result)
return wrapper
def sub_decorator(func):
def wrapper(self, other):
result = func(self, other)
return Sub(result)
return wrapper
class Value(IValue):
def __init__(self, value):
self.value = value
def __int__(self):
return self.value
@add_decorator
def __add__(self, other):
return self.value + other.value
@sub_decorator
def __sub__(self, other):
return self.value - other.value
class Add(IValue):
def __init__(self, value):
self.value = value
def __int__(self):
return self.value
def __add__(self, other):
return Add(self.value + other.value)
def __sub__(self, other):
return Sub(self.value - other.value)
class Sub(IValue):
def __init__(self, value):
self.value = value
def __int__(self):
return self.value
def __add__(self, other):
return Add(self.value + other.value)
def __sub__(self, other):
return Sub(self.value - other.value)
value1 = Value(int(input("Please give the largest number: ")))
value2 = Value(int(input("Please give the smallest number: ")))
print("\nAddition: ", int(value1 + value2))
print("Subtraction: ", int(value1 - value2))
print("Adding 50 to first number then subtracting the second: ", int((value1 + 50) - value2))
I asked it to make sure these are Decorators in my code
said it was!
idk if these are implemented right but it functions....
wait....
te add_decorator and sub are decorators
the UML wants strings not ints
does he not want the addition done????
how will that work??
__str__self()
thats a function on the class
__str__ is a function for console output formatting
also why does your add and sub have the other function
like add has sub as well
and sub has add as well
technically... that'd be __repr__
__str is for anything that converts it to string
beause each class has to implement the functions in IValue
doesnt pythons print call __str__ implicitly?
dont put them in IValue?
thats some decent code actually.
the problem it solves makes no sense though.. but the code looks decent
we need to be able to use the methods recursively
thats not shown in the UML
it says so in the description
this
the problem statement is so bad.. if that was done better it'd be a better assignment
it doesnt even mention an add or sub class
oh wait
the fuck is this assignment
from abc import ABC, abstractmethod
class IValue(ABC):
@abstractmethod
def __str__(self):
pass
class Value(IValue):
def __init__(self, value):
self.value = value
def __str__(self):
return str(self.value)
class Add(IValue):
def __init__(self, left, right):
self.left = left
self.right = right
def __str__(self):
return str(self.left) + " + " + str(self.right)
class Sub(IValue):
def __init__(self, left, right):
self.left = left
self.right = right
def __str__(self):
return str(self.left) + " - " + str(self.right)
value1 = Value(int(input("Please give the largest number: ")))
value2 = Value(int(input("Please give the smallest number: ")))
print("\nAddition: ", Add(value1, value2))
print("Subtraction: ", Sub(value1, value2))
print("Adding 50 to first number then subtracting the second: ", Add(value1, Sub(Value(50), value2)))
fixed it
has no decorators
yeah, but where are the decorators?
also wouldnt you just use the deocrators themselves on the variable?
like the code before didnt really use the decorators efficiently either
no it was weird
or can python only decorate funcs
By definition, a decorator is a function that takes another function and extends the behavior of the latter function without explicitly modifying it.
I dont get it ;-;
neither do i
well, I get it but IDK how to code it
oh really? i dont understand the problem
same
the assignment sounds like an unbeatable problem id have nightmares about
it doesnt make sense but in a dream id accept it
:/
def this_is_the_function_it_wraps():
...something
def Add(func):
def wrapper(left, right):
return func(left) + func(right)
return wrapper
def Sub(func):
def wrapper(left, right):
return func(left) - func(right)
return wrapper
@Add
def add_values(value1, value2):
return value1.value + value2.value
@Sub
def sub_values(value1, value2):
return value1.value - value2.value
value1 = Value(int(input("Please give the largest number: ")))
value2 = Value(int(input("Please give the smallest number: ")))
print("\nAddition: ", add_values(value1, value2))
print("Subtraction: ", sub_values(value1, value2))
print("Adding 50 to first number then subtracting the second: ", add_values(value1, Sub(Value(50), value2)))
this? but I need the IValue too UGH
if that assignment was given to me, i'd write something else (and more fun) to demonstrate that i understand decorators lol
I dont understand them 😢
and IDK enough about python to do this properly
if this was Java it would be a lot easier for me
how would you do this in java?
are decorators different in java?
as in.. the meaning of decorators?
the problem seems to require a java implementation as it looks like decorators have a different meaning in java
.-.
like really different
i have to use Python :/
you cant
maaybe
a decorator can alter a class and add add and sub functions to it.
but you should really use inheritance for that.
i dont know anymore, ive spend too many brain cycles on this
and need to sleep
from abc import ABC, abstractmethod
class IValue(ABC):
@abstractmethod
def __call__(self):
pass
class Value(IValue):
def __init__(self, value):
self.value = value
def __call__(self):
return self.value
def Add(func):
def wrapper(left: IValue, right: IValue):
return func(left) + func(right)
return wrapper
def Sub(func):
def wrapper(left: IValue, right: IValue):
return func(left) - func(right)
return wrapper
def main():
value1 = Value(int(input("Please give the largest number: ")))
value2 = Value(int(input("Please give the smallest number: ")))
add_values = Add(Value)(value1, value2)
sub_values = Sub(Value)(value1, value2)
print("\nAddition: ", add_values())
print("Subtraction: ", sub_values())
print("Adding 50 to first number then subtracting the second: ", Add(Value)(Value(50), Sub(Value)(value1, value2))())
if __name__ == "__main__":
main()
hhmmm
would this work?????
try it
fuckong phone call .-.
crashes
add_values = Add(Value)(value1, value2)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "Q2-Abstract-AI.py", line 17, in wrapper
return func(left) + func(right)
~~~^
TypeError: unsupported operand type(s) for +: 'Value' and 'Value'
from abc import ABC, abstractmethod
class IValue(ABC):
@abstractmethod
def __call__(self):
pass
class Value(IValue):
def __init__(self, value):
self.value = value
def __call__(self):
return self.value
def Add(func):
def wrapper(left: IValue, right: IValue):
return func(left) + func(right)
return wrapper
def Sub(func):
def wrapper(left: IValue, right: IValue):
return func(left) - func(right)
return wrapper
@Add
def add_values(value1: IValue, value2: IValue):
return value1() + value2()
@Sub
def sub_values(value1: IValue, value2: IValue):
return value1() - value2()
def main():
value1 = Value(int(input("Please give the largest number: ")))
value2 = Value(int(input("Please give the smallest number: ")))
print("\nAddition: ", add_values(value1, value2))
print("Subtraction: ", sub_values(value1, value2))
print("Adding 50 to first number then subtracting the second: ", add_values(Value(50), sub_values(value1, value2)))
if __name__ == "__main__":
main()
I just get error
Traceback (most recent call last): File "Q2-Abstract-AI.py", line 42, in <module> main() File "Q2-Abstract-AI.py", line 37, in main print("\nAddition: ", add_values(value1, value2)) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "Q2-Abstract-AI.py", line 17, in wrapper return func(left.__call__()) + func(right.__call__()) ^^^^^^^^^^^^^^^^^^^^^ TypeError: add_values() missing 1 required positional argument: 'value2'
You're not using the decorators
how use?
Oh wait you are
also, the UML calls for only one value being used....
do we just hardcode a second value?
But they don't provide 2 args to the called function. And what are they even doing
there is no sample output
Ok, really out now
gotta love functional programming
ok fuck this question..need to try the next one :/
Suppose we want to buy a stock for some amount, at some given price, and we have to strategize to decide, depending upon the strategy, we will change the amount for which we want to buy the stock. And we will change the price at which we would like to buy the stock. Assume that we have two strategies, one is aggressive, and one is passive. If we are moving with aggressive strategy, then what we will do is we will invest our whole amount at the current price of the stock. And if we are moving with the passive strategy, then what we will do is we would invest only 50% of the amount and that to at 90% of the current price. So, we will wait in this case so that the stock price comes down to the 90% of its current one, and then only we will invest, and we will invest only half of our amount i.e., 50%. So, these are the two strategies which we would like to use and whenever we are buying the stock, we will specify with which strategy we are moving with. Use python to demonstrate above concept of strategy design pattern.
i really wonder why your java/c# position only has python questions
SAME
.-.
maybe setting up the IDE to run this code would take too much time for them .-. instead of just runing a single .py file at terminal
Im am using PyCharm
Why does Python want two lines of blank space between function defs?
How do I turn these into BCNF tables???
They should already be 3NF
Customer (custNo, custName) Outlet (outletNo, outletLoc) Car (carReg, make, model) CustomerCar (custNo, id) Car (carReg, id): Hire (hireNo, hireDate, custNo, carReg, outletNo) HireOutlet (hireNo, outletNo)
different job offer
did you learn any database engineering?
yes
but up to 3NF
BCNF seems to be 3NF but with whatever "X should be a superkey for every functional dependency (FD) X−>Y in a given relation. " means
bump
