473,654 Members | 3,074 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 1383
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
2457
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 about Python's future prospects. I submit that the future expansion of Python usage is constrained by Python's lack of a CPAN-like facility, and I submit that without a CPyAN Python will never even get close to achieving the degree of...
16
44590
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 at http://www.python.org but nothing concrete there
3
1609
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 are implemented in Python are there any documents or articles about it, which I can read and get an idea. Thanks,
1
2657
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 required. My document looks something like this: <a> <b> <c/> </b> <b/>
122
7825
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 has largest community/buzz about it?
50
5697
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
1020
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 simplicity and elegance. So we're asking for your help. If you submit the text that we end up using, I'll send you 3 T-Shirts (1 seems too cheap, and there is always wear-and-tear, one for your cat, etc.). If we have extra T-Shirts, we might...
2
2459
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 is concerned. I am going to develop a accounting software that can work on the console and accessed through ssh from other terminals. I will like to use the curses or ncurses library for the menus and the input forms with add, save, delete,...
38
1835
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 minor experiments with this and Pyro looks interesting and like a good implementation of what I want. I've got a couple of questions though: 1) Has anyone had any experience with Pyro, and if so, have you had any stability, or memory use...
43
4305
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 python interpreter uses GIL(Global Interpreter Lock) for internal bookkeeping. The later allows only one python byte-code instruction to be executed at a time even if you have a multiprocessor computer. To overcome this limitation, I've created...
0
8376
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8708
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8594
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7307
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1596
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.