473,503 Members | 11,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to add add hits matches with python

3 New Member
How can I add hits and matches in this source code?

Expand|Select|Wrap|Line Numbers
  1. import random
  2. guessCount = 0
  3. num = random.randrange(10,99)
  4. print "Find the mistery number between 10 and 98"
  5. guess = input("Type in your guess: ")
  6. guessCount +=1
  7. while num != guess:
  8.     if guess < num:
  9.         print "Too low! Guess higher."
  10.     else:
  11.         print "Too high! Guess lower."
  12.     guess = input("Guess again: ")
  13.     guessCount = guessCount + 1
  14.     print ("Guesses: "), guessCount
  15. print "Correct!"
  16.  
Thanks :)
May 9 '10 #1
4 1373
Glenton
391 Recognized Expert Contributor
What do you mean? I don't know if you can or not, but it's probably possible ;P
May 10 '10 #2
marcelloc88
3 New Member
I mean. U guess a number. The mistery number is 62.
you guess, 50. So, u will have 1 hit and 0 matches...
If u don't get it tell me ;) I will explain it better ;)
May 10 '10 #3
Glenton
391 Recognized Expert Contributor
It would probably also help if you used code tags, so we could actually see what was going on. Without indentation, it's pretty difficult to read python!

But this might serve your purpose:
Expand|Select|Wrap|Line Numbers
  1. import random
  2.  
  3. #Create an infinite loop for the games
  4. guessCount=0
  5. gameNo=0
  6. matches=0
  7. while True:
  8.     gameNo+=1
  9.     print "Game: ",gameNo
  10.     num=random.randrange(10,100)
  11.     print "Find the mystery number between 10 and 98"
  12.     guess=input("Type in your guess (0 to exit): ")
  13.     if guess==0: break
  14.     guessCount+=1
  15.     while num != guess:
  16.         if guess < num:
  17.             print "Too low! Guess higher."
  18.         elif guess > num:
  19.             print "Too high! Guess lower."
  20.         guess=input("Guess again (0 to end game): ")
  21.         if guess==0: break
  22.         guessCount+=1
  23.     else:
  24.         print "Correct!"
  25.         matches+=1
  26.     print "Answer was ",num
  27.     print "Guesses/hits: ", guessCount
  28.     print "Matches: ", matches
  29.  
May 10 '10 #4
marcelloc88
3 New Member
Thank you so much, that helped! :)
May 10 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

29
2431
by: Stephen Ferg | last post by:
I am a very satisfied user of Python and have been for number of years. I would never willing use another language. I wish all good things for Python, and that moves me to express some thoughts...
16
44573
by: BOOGIEMAN | last post by:
Beginners question, but really what can you do with it ? How hard is Python to learn compared with other languages (let's say C#). Can you make fullscreen game with it (for example) ? I've looked...
3
1598
by: Emre Turkay | last post by:
Hi Folks, I am designing a tool, in which there are dynamic types and variables with these types. In this respect, it is more like an interpreted language design. I wonder how these issues...
1
2649
by: Steve Taylor | last post by:
I'm experiencing bad performance with certain kinds of match queries. Using a custom XPathNavigator that wraps the usual navigator I can see that many more node visits are performed than should be...
122
7738
by: seberino | last post by:
I'm interested in knowing which Python web framework is most like Ruby on Rails. I've heard of Subway and Django. Are there other Rails clones in Python land I don't know about? Which one...
50
5651
by: diffuser78 | last post by:
I have just started to learn python. Some said that its slow. Can somebody pin point the issue. Thans
0
1015
by: Brian Quinlan | last post by:
The Vancouver Python Workshop organizers are having problems coming up with text for our T-Shirts (don't worry: we already have the graphics figured out). We want something that matches Python's...
2
2454
by: krishnakant Mane | last post by:
hello, I am a new member to this list. I am Krishnakant from India, Mumbai. I have been coding in python for quite some time and now I am at the intermediate level of programming as far as python...
38
1806
by: writeson | last post by:
Hi all, At work I'm considering proposing a solution for our distributed processing system (a web based shopping cart that feeds an actual printing production line) based on Pyro. I've done some...
43
4268
by: parallelpython | last post by:
Has anybody tried to run parallel python applications? It appears that if your application is computation-bound using 'thread' or 'threading' modules will not get you any speedup. That is because...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.