Re: Small newbie question

2006-02-12 Thread Astan Chee


Byte wrote:

>How would I do this: Write a program that simply outputs a ramdom (in
>this case) name of (for this example) a Linux distibution. Heres the
>code ive tryed:
>
>from random import uniform
>from time import sleep
>
>x = 2
>while x < 5:
>x = uniform(1, 5)
>if x >= 1 <= 1.999: print 'SuSE'
>elif x >= 2 <= 2.999: print 'Ubuntu'
>elif x >= 3 <= 3.999: print 'Mandriva'
>elif x >= 4 <= 4.999: print 'Fedora'
>sleep(2)
>  
>
But replace your if statement with this (which is similar), does work:
if 1 <= x <= 1.999: print 'SuSE'
elif 2 <= x <= 2.999: print 'Ubuntu'
elif 3 <= x <= 3.999: print 'Mandriva'
elif 4 <= x <= 4.999: print 'Fedora'

>It dosnt work: only keep printing SuSE. Please help,
>
>Thanks in advance,
> -- /usr/bin/byte
>
>  
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Small newbie question

2006-02-12 Thread Paul Rubin
> while x < 5:
> x = uniform(1, 5)
> if x >= 1 <= 1.999: print 'SuSE'
> ...
> It dosnt work: only keep printing SuSE. Please help,

Try this:

 x = 27.6
 if x >= 1 <= 1.999: print 'SuSE'

It prints 'SuSE' because the test is written incorrectly.  You want:

if 1 <= x <= 1.999: print 'SuSE'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Small newbie question

2006-02-12 Thread Byte
Great stuff, thanks:

 -- /usr/bin/byte

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Small newbie question

2006-02-12 Thread Tim Parkin
Byte wrote:
> How would I do this: Write a program that simply outputs a ramdom (in
> this case) name of (for this example) a Linux distibution. Heres the
> code ive tryed:
> 
> from random import uniform
> from time import sleep
> 
> x = 2
> while x < 5:
> x = uniform(1, 5)
> if x >= 1 <= 1.999: print 'SuSE'
> elif x >= 2 <= 2.999: print 'Ubuntu'
> elif x >= 3 <= 3.999: print 'Mandriva'
> elif x >= 4 <= 4.999: print 'Fedora'
> sleep(2)
> 
> It dosnt work: only keep printing SuSE. Please help,
> 
> Thanks in advance,
>  -- /usr/bin/byte
> 


import random
dist = ['suse','ubuntu','mandriva','fedora']
random.choice(dist)

is that ok?

Tim Parkin

[1] http://www.python.org/doc/lib/module-random.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Small newbie question

2006-02-12 Thread Byte
How would I do this: Write a program that simply outputs a ramdom (in
this case) name of (for this example) a Linux distibution. Heres the
code ive tryed:

from random import uniform
from time import sleep

x = 2
while x < 5:
x = uniform(1, 5)
if x >= 1 <= 1.999: print 'SuSE'
elif x >= 2 <= 2.999: print 'Ubuntu'
elif x >= 3 <= 3.999: print 'Mandriva'
elif x >= 4 <= 4.999: print 'Fedora'
sleep(2)

It dosnt work: only keep printing SuSE. Please help,

Thanks in advance,
 -- /usr/bin/byte

-- 
http://mail.python.org/mailman/listinfo/python-list