| | |
Need help please!
Thread Solved |
•
•
Join Date: Aug 2008
Posts: 146
Reputation:
Solved Threads: 42
1
#2 20 Days Ago
You should try to post some code yourself.
Can give you some tips.
Can give you some tips.
Python Syntax (Toggle Plain Text)
>>> for i in range(0,7): a = random.randint(0,100) print a 79 21 69 60 28 68 0 >>>
Python Syntax (Toggle Plain Text)
>>> >>> 1 % 2 1 >>> 2 % 2 0 >>> 3 % 2 1 >>> 4 % 2 0 >>>
Last edited by snippsat; 20 Days Ago at 8:44 pm.
•
•
Join Date: Aug 2008
Posts: 146
Reputation:
Solved Threads: 42
1
#4 20 Days Ago
One more,now start to think how to put this together.
Python Syntax (Toggle Plain Text)
>>> count = 0 >>> a = 55 >>> if a % 2 == 1: count += 1 print 'odd', count else: print 'even' odd 1 >>>
Last edited by snippsat; 20 Days Ago at 9:07 pm.
0
#6 20 Days Ago
Try not to over think the problem. You should only need 4 variables in this problem. even, odd, randNum, and i. Variable i is used to control the for loop, randNum is used to hold a random number for even or odd comparison, even and odd are incremented based on the comparison of the randNum. Then print your results to the console. Also what type of computer course are you taking?
Last edited by ShadyTyrant; 20 Days Ago at 2:00 am.
•
•
Join Date: Apr 2009
Posts: 41
Reputation:
Solved Threads: 10
0
#7 20 Days Ago
dude just combine everything snippsat posted he basically wrote you the programme it's right there, just think about it
create a loop from 1 to 100
generate random number and store in a variable
if the number is odd add 1 to odd variable
else add 1 to even variable
print odd and even variables
create a loop from 1 to 100
generate random number and store in a variable
if the number is odd add 1 to odd variable
else add 1 to even variable
print odd and even variables
•
•
Join Date: Aug 2008
Posts: 146
Reputation:
Solved Threads: 42
0
#8 19 Days Ago
Next time if you post here try to post some code.
That will show that you but some effort in to it.
With homework we will not just post finish code.
Here is one soultion,as extra i put number odd/even number in a list.
Try to understand what going on,ask question if you not sure an we break it down.
That will show that you but some effort in to it.
With homework we will not just post finish code.
Here is one soultion,as extra i put number odd/even number in a list.
Try to understand what going on,ask question if you not sure an we break it down.
Python Syntax (Toggle Plain Text)
import random count_odd = 0 count_even = 0 odd_list = [] even_list = [] for i in range(0,100): rand_n = random.randint(0,100) if rand_n % 2 == 1: count_odd += 1 odd_list.append(rand_n) else: count_even += 1 even_list.append(rand_n) print 'Out off 100 random number %d was odd\nHere are the numbers->\n' % (count_odd) print odd_list # Here we do a check that it`s 100 number print 'Out off %d random number %d was even\nHere are the numbers->\n' % (count_even + count_odd, count_even) print even_list '''my output-> Out off 100 random number 44 was odd Here are the numbers-> [53, 67, 27, 37, 97, 75, 89, 87, 65, 81, 31, 85, 85, 33, 13, 13, 27, 5, 75, 37, 73, 39, 53, 71, 53, 27, 23, 1, 13, 19, 29, 9, 13, 45, 19, 31, 63, 27, 33, 43, 51, 61, 35, 35] Out off 100 random number 56 was even Here are the numbers-> [2, 2, 16, 16, 34, 14, 70, 22, 30, 2, 74, 90, 28, 36, 100, 74, 48, 8, 40, 64, 54, 94, 54, 56, 16, 4, 94, 66, 18, 12, 36, 100, 8, 18, 54, 16, 72, 16, 20, 60, 28, 6, 38, 10, 62, 88, 98, 90, 54, 26, 50, 38, 66, 76, 42, 12] '''
![]() |
Other Threads in the Python Forum
- Previous Thread: Please help me get past this problem
- Next Thread: Importing Graphics Module
| Thread Tools | Search this Thread |
abrupt ansi anti apache approximation array assignment avogadro backend beginner binary bluetooth book builtin calculator character cmd converter countpasswordentry curved customdialog dan08 decimals dictionaries dictionary dynamic exe file float format function gnu graphics heads homework http ideas import inches input java leftmouse library line lines linux list lists loop module mouse mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar py2exe pygame python random recursion redirect scrolledtext software sqlite statictext statistics string strings sum table terminal text textarea thread threading time tlapse trick tuple tutorial twoup ubuntu unicode urllib urllib2 variable wordgame write wxpython xlib





