Re: Python homework

2017-12-14 Thread edmondo . giovannozzi
Il giorno martedì 12 dicembre 2017 00:30:24 UTC+1, jlad...@itu.edu ha scritto: > On Thursday, December 7, 2017 at 4:49:52 AM UTC-8, edmondo.g...@gmail.com > wrote: > > > import numpy > > I teach Python to students at varying levels. As much as I love and use > Numpy in my regular work, I try

Re: Answers to homework questions [WAS]: Re: Python homework

2017-12-14 Thread Rustom Mody
On Thursday, December 14, 2017 at 7:02:56 PM UTC+5:30, Rustom Mody wrote: > On Thursday, December 14, 2017 at 3:53:21 PM UTC+5:30, Lorenzo Sutton wrote: > > Hi Roger, > > > > On 13/12/17 23:31, ROGER GRAYDON CHRISTMAN wrote: > > > On Wed, Dec 13, 2017, Lorenzo Sutton wrote: > > >> > > > On 05/12/1

Re: Answers to homework questions [WAS]: Re: Python homework

2017-12-14 Thread Rustom Mody
On Thursday, December 14, 2017 at 3:53:21 PM UTC+5:30, Lorenzo Sutton wrote: > Hi Roger, > > On 13/12/17 23:31, ROGER GRAYDON CHRISTMAN wrote: > > On Wed, Dec 13, 2017, Lorenzo Sutton wrote: > >> > > On 05/12/17 06:33, nick martinez2 via Python-list wrote: > >>> I have a question on my homework.

Re: Answers to homework questions [WAS]: Re: Python homework

2017-12-14 Thread Rhodri James
On 14/12/17 10:22, Lorenzo Sutton wrote: Hi Roger, On 13/12/17 23:31, ROGER GRAYDON CHRISTMAN wrote: On Wed, Dec 13, 2017, Lorenzo Sutton wrote: On 05/12/17 06:33, nick martinez2 via Python-list wrote: I have a question on my homework. [...] For this kind of problem I think the collection

Answers to homework questions [WAS]: Re: Python homework

2017-12-14 Thread Lorenzo Sutton
Hi Roger, On 13/12/17 23:31, ROGER GRAYDON CHRISTMAN wrote: On Wed, Dec 13, 2017, Lorenzo Sutton wrote: On 05/12/17 06:33, nick martinez2 via Python-list wrote: I have a question on my homework. [...] For this kind of problem I think the collections module [1] can be very useful. In this c

Re: Python homework

2017-12-13 Thread jladasky
On Thursday, December 7, 2017 at 7:11:18 AM UTC-8, Rhodri James wrote: > Sigh. Please don't do people's homework for them. It doesn't teach > them anything. Now Nick had got 90% of the way there and shown his > working, which is truly excellent, but what he needed was for someone to > hint a

Re: Python homework

2017-12-13 Thread Terry Reedy
On 12/13/2017 8:28 AM, bo...@choices.random.py wrote: nick.martin...@aol.com (nick martinez2) writes: def rollDie(number): rolls = [0] * 6 for i in range(0, number): roll=int(random.randint(1,6)) One could just as well use randint(0, 5) and skip the -1 below. rol

Re: Python homework

2017-12-13 Thread ROGER GRAYDON CHRISTMAN
On Wed, Dec 13, 2017, Lorenzo Sutton wrote: > On 05/12/17 06:33, nick martinez2 via Python-list wrote: >> I have a question on my homework. My homework is to write a program in >which >> the computer simulates the rolling of a die 50 times and then prints >> (i). the most frequent side of the die (

Re: Python homework

2017-12-13 Thread Chris Angelico
On Thu, Dec 14, 2017 at 3:23 AM, wrote: > from random import randint > > rolls = [randint(1, 6) for x in range(50)] > print("Average: %s" % (sum(rolls) / len(rolls))) > print("Most Common: %s" % max(rolls, key=rolls.count)) Great demo of a bad algorithm. :) ChrisA -- https://mail.python.org/ma

Re: Python homework

2017-12-13 Thread paul
from random import randint rolls = [randint(1, 6) for x in range(50)] print("Average: %s" % (sum(rolls) / len(rolls))) print("Most Common: %s" % max(rolls, key=rolls.count)) -- https://mail.python.org/mailman/listinfo/python-list

Re: Python homework

2017-12-13 Thread boffi
nick.martin...@aol.com (nick martinez2) writes: > def rollDie(number): > rolls = [0] * 6 > for i in range(0, number): > roll=int(random.randint(1,6)) > rolls[roll - 1] += 1 > return rolls def rollDie(number): from random import choices return choices((1,2,3,4,5

Re: Python homework

2017-12-13 Thread Lorenzo Sutton
Hi, On 05/12/17 06:33, nick martinez2 via Python-list wrote: I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 times and then prints (i). the most frequent side of the die (ii). the average die value of all rolls. For t

Re: Python homework

2017-12-11 Thread jladasky
On Thursday, December 7, 2017 at 4:49:52 AM UTC-8, edmondo.g...@gmail.com wrote: > import numpy I teach Python to students at varying levels. As much as I love and use Numpy in my regular work, I try to avoid showing beginning Python students solutions that require third-party packages. Her

Re: Python homework

2017-12-11 Thread Python
On Tue, Dec 05, 2017 at 09:02:54PM +1200, ssghotra1997 wrote: > for i in range(num): > rolls = int(random.randint(1, 6)) > if rolls == 1: > sides['One'] += 1 [...] Using integers as the key makes the code a bit shorter... That approach is also better if you're usin

Re: Python homework

2017-12-08 Thread ssghotra1997
import random def rollDie(num): sides = {'One':0, 'Two':0,'Three':0,'Four':0,'Five':0,'Six':0} for i in range(num): rolls = int(random.randint(1, 6)) if rolls == 1: sides['One'] += 1 if rolls == 2: sides['Two'] += 1 if rolls == 3:

Re: Python homework

2017-12-08 Thread MRAB
On 2017-12-06 01:33, nick.martinez2--- via Python-list wrote: > I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 > times and then prints > (i). the most frequent side of the die > (ii). the average die value of all rolls. >

Re: Python homework

2017-12-07 Thread Rhodri James
On 07/12/17 13:19, Mario R. Osorio wrote: On Tuesday, December 5, 2017 at 8:33:52 PM UTC-5, nick martinez wrote: I have a question on my homework. [snip] Just my 2 cents: Sigh. Please don't do people's homework for them. It doesn't teach them anything. Now Nick had got 90% of the way

Re: Python homework

2017-12-07 Thread Mario R. Osorio
On Tuesday, December 5, 2017 at 8:33:52 PM UTC-5, nick martinez wrote: > I have a question on my homework. My homework is to write a program in which > the computer simulates the rolling of a die 50 > times and then prints > (i). the most frequent side of the die > (ii). the average die value o

Re: Python homework

2017-12-07 Thread edmondo . giovannozzi
Il giorno mercoledì 6 dicembre 2017 02:33:52 UTC+1, nick martinez ha scritto: > I have a question on my homework. My homework is to write a program in which > the computer simulates the rolling of a die 50 > times and then prints > (i). the most frequent side of the die > (ii). the average die val

Re: Python homework

2017-12-06 Thread ssghotra1997
On Wednesday, December 6, 2017 at 9:28:26 PM UTC+11, D'Arcy Cain wrote: > On 12/05/2017 07:33 PM, nick.martinez2--- via Python-list wrote: > > I have a question on my homework. My homework is to write a program in > > which the computer simulates the rolling of a die 50 > > times and then prints >

Re: Python homework

2017-12-06 Thread Bill
I think carelessness in choosing variable names may be at the root of the problem. nick.martin...@aol.com wrote: I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 times and then prints (i). the most frequent side of the

Re: Python homework

2017-12-06 Thread D'Arcy Cain
On 12/05/2017 07:33 PM, nick.martinez2--- via Python-list wrote: I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 times and then prints (i). the most frequent side of the die (ii). the average die value of all rolls. I wr

Re: Python homework

2017-12-05 Thread ssghotra1997
import random def rollDie(num): sides = {'One':0, 'Two':0,'Three':0,'Four':0,'Five':0,'Six':0} for i in range(num): rolls = int(random.randint(1, 6)) if rolls == 1: sides['One'] += 1 if rolls == 2: sides['Two'] += 1 if rolls == 3:

Re: Python homework

2017-12-05 Thread MRAB
On 2017-12-06 01:33, nick.martinez2--- via Python-list wrote: I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 times and then prints (i). the most frequent side of the die (ii). the average die value of all rolls. I wrote