| | |
Need help please!
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
1
#2 Nov 3rd, 2009
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; Nov 3rd, 2009 at 8:44 pm.
1
#4 Nov 3rd, 2009
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; Nov 3rd, 2009 at 9:07 pm.
0
#6 Nov 4th, 2009
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; Nov 4th, 2009 at 2:00 am.
•
•
Join Date: Apr 2009
Posts: 56
Reputation:
Solved Threads: 11
0
#7 Nov 4th, 2009
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
0
#8 Nov 4th, 2009
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
Views: 274 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied address ansi backend beginner changecolor class code conversion coordinates copy curves customdialog dan08 dictionary directory dynamic edit examples excel feet file float font format ftp function generator getvalue gui halp homework i/o images import info input ip java line linux list lists loop mouse mysql newb number numbers output panel parsing path port prime print program programming projects py2exe pygame pyqt python queue random rational recursion recursive schedule screensaverloopinactive scrolledtext searchingfile server ssh stamp statictext string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial type ubuntu unicode url urllib urllib2 variable whileloop windows write wxpython





