Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 28th, 2012, 09:49 PM
grimofdoom grimofdoom is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 2 grimofdoom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 38 sec
Reputation Power: 0
Help!??

I am fairly new to python, so i thought i would mess around and make a command program. What it does is send out 200 numbers randomly generated of 1's and 2's and then counts them and displays the outcome and the total number count. I was wondering if someone could help me because i want the outcome and the print line on one line. here is my script:
Code:
total=0
sone=0
stwo=0

while total<200:
 import random
 num = random.randint(1,2)
 print num
 total=total+1
 if num==2:
  stwo=stwo+1
 if num==1:
  sone=sone+1
 if total==200:
  print "This program is about to start counting the 1's and 2's"
print "this program will now count the total of 1's and 2's"
print ""
print ""
print "*****************************************************************************"
print "twos were found in this run,the total count of ones are:"
print sone
print "---"
print"the total 2's that show up are:"
print stwo
print "---"
print "the total number of 1's and 2's used is :"
print total

Reply With Quote
  #2  
Old July 28th, 2012, 10:25 PM
grimofdoom grimofdoom is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 2 grimofdoom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 38 sec
Reputation Power: 0
I made an edit to my file and now it doesnt work, the raw data seams to not send the data right or something:
Code:
total=0
sone=0
stwo=0

var=raw_input("Enter a number: ")
while total<var:
 import random
 num = random.randint(1,2)
 print num
 total=total+1
 if num==2:
  stwo=stwo+1
 if num==1:
  sone=sone+1
 if total==var:
  print "This program is about to start counting the 1's and 2's"
print "this program will now count the total of 1's and 2's"
print ""
print ""
print "*****************************************************************************"
print "twos were found in this run,the total count of ones are:"
print sone
print "---"
print"the total 2's that show up are:"
print stwo
print "---"
print "the total number of 1's and 2's used is :"
print total

Reply With Quote
  #3  
Old July 29th, 2012, 06:28 AM
Quackajack Quackajack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 39 Quackajack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 49 m 43 sec
Reputation Power: 1
I think the answer you are looking for is use a comma to separate the text and and the value on the print line. For example

Code:
print "Total count of ones are:", sone
print "---"
print "Total 2's that show up are:", stwo
print "---"
print "Total number of 1's and 2's used is :", total


PS You don't need the import line in the loop; move it to the top. You are actually calling import random 200 times; Python will know it has already imported it before and skip the last 199 requests.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Help!??

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap