How can I add hits and matches in this source code? - import random
-
guessCount = 0
-
num = random.randrange(10,99)
-
print "Find the mistery number between 10 and 98"
-
guess = input("Type in your guess: ")
-
guessCount +=1
-
while num != guess:
-
if guess < num:
-
print "Too low! Guess higher."
-
else:
-
print "Too high! Guess lower."
-
guess = input("Guess again: ")
-
guessCount = guessCount + 1
-
print ("Guesses: "), guessCount
-
print "Correct!"
-
Thanks :)
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
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 ;)
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: - import random
-
-
#Create an infinite loop for the games
-
guessCount=0
-
gameNo=0
-
matches=0
-
while True:
-
gameNo+=1
-
print "Game: ",gameNo
-
num=random.randrange(10,100)
-
print "Find the mystery number between 10 and 98"
-
guess=input("Type in your guess (0 to exit): ")
-
if guess==0: break
-
guessCount+=1
-
while num != guess:
-
if guess < num:
-
print "Too low! Guess higher."
-
elif guess > num:
-
print "Too high! Guess lower."
-
guess=input("Guess again (0 to end game): ")
-
if guess==0: break
-
guessCount+=1
-
else:
-
print "Correct!"
-
matches+=1
-
print "Answer was ",num
-
print "Guesses/hits: ", guessCount
-
print "Matches: ", matches
-
Thank you so much, that helped! :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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,
|
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/>
|
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?
| |
by: diffuser78 |
last post by:
I have just started to learn python. Some said that its slow. Can
somebody pin point the issue.
Thans
|
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...
|
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,...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |