Python Forum
yet another homework question
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
yet another homework question
#1
Quote:Write a program that flips a coin 100 times and then tells you
the number of heads and tails.

the solution should not include "lists" and such a they were not learned yet in the book.

the book is called "Python Programming for the Absolute Beginner, 3rd Edition"

can you tell me the answer?

:)
Reply
#2
Quote:can you tell me the answer?

You need to provide your attempt at writing the code yourself.
We are glad to help, but should not write your homework for you.
Reply
#3
(Aug-12-2018, 10:34 AM)HakolYahol Wrote: can you tell me the answer?
Yes, we can. But it's your homework and we won't do it.
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
#4
i still have some problem with figuring out how to solve questions that are given to me.

i will read without answering questions then because the mental effort is futile.

too bad the book does not include answers
Reply
#5
Quote:too bad the book does not include answers
why take the course then?
Reply
#6
(Aug-12-2018, 06:48 PM)Larz60+ Wrote:
Quote:too bad the book does not include answers
why take the course then?

it's not a course. it's just a book. and i want to try learning anyway. maybe at some point i will be able to understand the concept better

so what do you actually say?
Reply
#7
(Aug-13-2018, 03:46 PM)HakolYahol Wrote: so what do you actually say?

it doesn't matter if it is book(self-study resource) or a course. If you don't gain enough/solid knowledge that will allow you to solve the problems/exercises yourself then why you waste time with this particular book/course? not all learning resources are good fit for everybody. I don't say it's bad/good one - I don't know it, but maybe the material is not presented in the right way FOR YOU.
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
#8
Understanding each elementary part of any system, software, engineering, or whatever may be boring, if looked at the wrong way, but it can be an adventure in learning. Understanding how each simple part works makes designing a larger system easy, and more gratifying because you know what it's going to do before constructing it.

If you don't follow these simple rules, you'll end up with something like Microsoft word!
Reply
#9
I agree that you should try harder by yourself. Yet I'm learning too and specially trying hard to manage loops. Although I think this exercise was not really hard to solve.
import random
heads=0
i=0
for i in range(99):
  i+= 1
  heads_count = random.randrange(2)
  if heads_count == 0:
    heads_count = 0
  elif heads_count == 1:
    heads_count = 1
    heads+=1

print("Number of heads", heads, ".  Number of tails", 100 - heads)
Reply
#10
I recommend using pythonista's best friend - interactive interpretator. You can list all available methods and get help on them. Python names are quite descriptive and just scanning available methods and trying out most promising ones may help you find solution for your problem.

>>> import random
>>> random.         # 2 x TAB key
random.betavariate(     random.lognormvariate(  random.seed(           
random.BPF              random.normalvariate(   random.setstate(       
random.choice(          random.NV_MAGICCONST    random.SG_MAGICCONST   
random.choices(         random.paretovariate(   random.shuffle(        
random.expovariate(     random.randint(         random.SystemRandom(   
random.gammavariate(    random.Random(          random.triangular(     
random.gauss(           random.random(          random.TWOPI           
random.getrandbits(     random.randrange(       random.uniform(        
random.getstate(        random.RECIP_BPF        random.vonmisesvariate(
random.LOG4             random.sample(          random.weibullvariate( 
>>> help(random.choice)
Help on method choice in module random:

choice(seq) method of random.Random instance
    Choose a random element from a non-empty sequence.
(END)
>>> random.choice(['heads', 'tails'])
'heads'
>>> random.choice(['heads', 'tails'])
'heads'
>>> random.choice(['heads', 'tails'])
'tails'
You don't need i = 0 because for-loop does it for you. If you want loop 100 times then:

for i in range(100):
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Homework help:While Loops question Midhat_School 6 3,073 Jul-26-2020, 10:23 AM
Last Post: pyzyx3qwerty
  IF ELSE Homework Question buckthimble 1 2,131 Mar-29-2020, 06:29 AM
Last Post: buran
  Python Homework Question OrcDroid123 1 2,363 Sep-01-2019, 08:44 AM
Last Post: buran
  Homework question dmhhfm 4 13,337 Apr-10-2019, 07:22 AM
Last Post: DeaD_EyE
  Beginner Python Homework Question (Calculate Gross Pay) matchamochi7 4 5,671 Nov-02-2018, 01:06 PM
Last Post: buran
  python in JES homework question, lsteffen 1 2,994 Feb-11-2018, 05:52 PM
Last Post: Taco_Town

Forum Jump:

User Panel Messages

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