Python Forum
Some exercises I need help with.
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Some exercises I need help with.
#2
One thing:
in the following code:
def prob_die(max_exp, outcome):
    counter = 0
    for _ in range(max_exp):
        s = random.randint(1,6) # roll
        if s==outcome:
            counter +=1
        return counter/max_exp
The for loop is worthless as stands because you return unconditionally after the first iteration
did you mean for the return to be part of the if==outcome statement? if so indent.
Reply


Messages In This Thread
RE: Some exercises I need help with. - by Larz60+ - Dec-02-2018, 04:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Mission Impossible : New to Python and 3 days to do theses exercises Kangaaxx 6 3,943 Aug-16-2018, 05:58 PM
Last Post: Kangaaxx
  3 Finance Python Exercises mmkthen 2 5,557 Oct-29-2017, 02:55 PM
Last Post: sparkz_alot
  One of my exercises is breaking my balls. Jei 14 14,185 Dec-03-2016, 03:35 PM
Last Post: Jei

Forum Jump:

User Panel Messages

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