Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Classes
#21
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)
Reply
#22
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#23
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 :(
Reply
#24
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#25
(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
Reply
#26
Still nothing...
Reply
#27
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-
Reply
#28
Well,thanks for helping me...
i failed!!
Reply
#29
Since there is no benefit for me now since I didn't submit the assignment can anyone show me the solution to this exercise?
Reply
#30
I will try and solve it but I hope so other more experienced will help you.
Reply


Forum Jump:

User Panel Messages

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