I have a problem. For me all is correct but when im trying to have a first guess cmd dont print "print("Lower...")" and neither "print("Higher...")" statement. after first try everything works good. Help me just to find a problem because i cant see anything. Thank You
Here is my source code: -
import random
-
-
print("\t\t\tWelcome to guess my number game!!!")
-
print("Please enter the number between 1 and 100")
-
-
number = random.randint(1, 100)
-
guess = int(input("Take a guess: "))
-
max_guess = 5
-
tries = 1
-
-
-
-
while guess != number:
-
guess = int(input("Take a guess: "))
-
tries += 1
-
-
if guess > number:
-
print("Lower...")
-
elif guess < number:
-
print("Higher...")
-
else:
-
print("Good you got it and it only tooked you ", tries, " tries!")
-
break
-
-
if tries == max_guess:
-
print("\n\nYou are out of tries")
-
break
-
-
-
-
-
-
input("\n\nPress Enter to exit")
-
Move your first guess under the while statement. Initialize tries to 0. I modified your code for Python 2.7: - import random
-
-
print "Welcome to guess my number game!!!"
-
print "Please enter the number between 1 and 100"
-
-
number = random.randint(1, 100)
-
print number
-
max_guess = 5
-
tries = 0
-
-
while True:
-
guess = int(raw_input("Take a guess: "))
-
tries += 1
-
if guess > number:
-
print "Lower..."
-
elif guess < number:
-
print "Higher..."
-
else:
-
print "Good you got it and it only tooked you", tries, "tries!"
-
break
-
if tries == max_guess:
-
print "\n\nYou are out of tries"
-
break
-
-
raw_input("\n\nPress Enter to exit")
4 1714
After changing " tries += 1 guess = int(input("Guess again: "))" from the beggining to the end of the loop it works ok but after you guess the number cmd doesnt want to print "print("Good you got it and it only tooked you ", tries, " tries!")". Maybe this code is a mess but im new in this. Just need some more experience. Thanks for help. -
import random
-
-
print("\t\t\tWelcome to guess my number game!!!")
-
print("Please enter the number between 1 and 100")
-
-
number = random.randint(1, 100)
-
guess = int(input("Take a guess: "))
-
max_guess = 5
-
tries = 1
-
-
while guess != number:
-
if guess > number:
-
print("Lower...")
-
elif guess < number:
-
print("Higher...")
-
else:
-
print("Good you got it and it only tooked you ", tries, " tries!")
-
break
-
guess = int(input("Guess again: "))
-
tries += 1
-
-
if tries == max_guess:
-
print("\n\nYou are out of tries")
-
break
-
-
-
input("\n\nPress Enter to exit")
-
bvdet 2,851
Expert Mod 2GB
Move your first guess under the while statement. Initialize tries to 0. I modified your code for Python 2.7: - import random
-
-
print "Welcome to guess my number game!!!"
-
print "Please enter the number between 1 and 100"
-
-
number = random.randint(1, 100)
-
print number
-
max_guess = 5
-
tries = 0
-
-
while True:
-
guess = int(raw_input("Take a guess: "))
-
tries += 1
-
if guess > number:
-
print "Lower..."
-
elif guess < number:
-
print "Higher..."
-
else:
-
print "Good you got it and it only tooked you", tries, "tries!"
-
break
-
if tries == max_guess:
-
print "\n\nYou are out of tries"
-
break
-
-
raw_input("\n\nPress Enter to exit")
Thanks, I using Python 3.4.3 but thank you. It was so easy that I feel stupid right now
bvdet 2,851
Expert Mod 2GB
You are welcome. Sometimes the obvious solution is the hardest to see.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dave |
last post by:
I have one auto number field in one table in sql server
2000.
I'm inserting new record using insert statement and am
not giving any value for that field as its auto number.
On the very next...
|
by: fatih kayaalp |
last post by:
Hi, i have imported an access database into sqlserver 2000. In access,
i have some table fields which were using automatic number as
datatype. But i see that there is not a datatype in sqlserver...
|
by: nicolas |
last post by:
Aim: scanf a number what random digit,split this number;
for example: input "5680"
output "5,6,8,0";
input "45"
output "4,5";
|
by: Mark Rae |
last post by:
Hi,
My R&D department has asked me to look at threading in a Web Service written
in C#, so I came up with the following code:
using System;
using System.ComponentModel;
using...
|
by: cathf |
last post by:
I am working on a program where the user guesses a random number generated in VB. The numbers entered by the user must be within the range 1 to 20, so the program has been validated. All valid...
|
by: arali |
last post by:
I have builed a database in access and using forms of Visual Basic6
The problem is this
I have a field Id which is of type long and autoincrement
Now when i create a form and run and type my...
|
by: istillshine |
last post by:
In my code I used NAN and isnan(x). I found they were convenient to
use. I also noticed that
older C standard does not support NAN and isnan(x).
When I compiled my program using:
gcc -Wall...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |