Python Forum
Help with Classes - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Help with Classes (/thread-16122.html)

Pages: 1 2 3 4


RE: Help with Classes - Lonewolf - Feb-16-2019

so i have something like that for coordinates:
a=[]
for j in range(11):
      x=random.randint(1,12)
for i in range(29):
      y=random.randint(1,29)
a.append(x,y)
as for shape it should go something like that?
b=[triangle,sphere]
random.suffle(b,random.random)
print(b)



RE: Help with Classes - buran - Feb-16-2019

You don't need the for loops when you generate x and y. With your code you will generate 11 x values and 29 y values, but at the end you will add just the last pair - 11th x and 29th y, all other are lost. see for yourself
a=[]
for j in range(11):
      x=random.randint(1,12)
      print('x={}'.format(x))
for i in range(29):
      y=random.randint(1,29)
      print('y={}'.format(y))
a.append((x,y))
print(a)
note that you need extra pair of brackets for the append.
when you get the x and y, you don't want to add them to list. you want to create instance of Triangle or Sphere class and use x and y when create that instance

the second snippet - it even doesn't run. Please, pay more attention.


RE: Help with Classes - Lonewolf - Feb-16-2019

ok thanks!
it's obvious now that i will never solve this exercise!!
i do not understand anything here.
Even if i study again and again and again classes and inheritance i won't make any progress :(


RE: Help with Classes - buran - Feb-16-2019

sorry, but I will not give you ready solution. Period. You either make an effort if you want any more help or just give up and enjoy the weekend. At least I am going to do that now.
(Feb-16-2019, 11:29 AM)Lonewolf Wrote: Even if i study again and again and again classes and inheritance i won't make any progress :(
and stop complain about classes and inheritance. we are part this stage long ago. you need to look into lops and lists. look into your textbook. using custom class is no different than any build-in class.


RE: Help with Classes - Lonewolf - Feb-16-2019

(Feb-16-2019, 11:46 AM)buran Wrote: sorry, but I will not give you ready solution. Period. You either make an effort if you want any more help or just give up and enjoy the weekend. At least I am going to do that now.
(Feb-16-2019, 11:29 AM)Lonewolf Wrote: Even if i study again and again and again classes and inheritance i won't make any progress :(
and stop complain about classes and inheritance. we are part this stage long ago. you need to look into lops and lists. look into your textbook. using custom class is no different than any build-in class.

loops and lists??
what to look exactly?in my textbooks are only simple examples.Not complicated like the ones this exercise needs.
Sorry if i made you lose your time with me.
if i give up i fail
but i don't get what i must do


RE: Help with Classes - Lonewolf - Feb-17-2019

Still nothing...


RE: Help with Classes - Lonewolf - Feb-17-2019

i tried something:
i created a list with all possible coordinates and then another list with the random 12:

import random
coordinates = []

for x in range(12):
  for y in range(30):
    coordinates.append((x, y))  

for i in range(12):
    lilo = random.choice(coordinates)
print(lilo)
but i used random.choice and not random.randit (as exercise says Sad )
now how i instatiate that with the shapes?
-i haven't succeeded yet in creating random shapeds though-


RE: Help with Classes - Lonewolf - Feb-18-2019

Well,thanks for helping me...
i failed!!


RE: Help with Classes - Lonewolf - Feb-18-2019

Since there is no benefit for me now since I didn't submit the assignment can anyone show me the solution to this exercise?


RE: Help with Classes - sonedap - Feb-18-2019

I will try and solve it but I hope so other more experienced will help you.