Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJackson Lai
3,538 PointsNumber Guessing Game (Reverse Ver.) + Questions
As Kenneth mentioned in the end of the video: To build a reverse version for the number guessing game as a challenge.
Here is my code and I would like you guys to review my code and help me to improve.
And few questions:
Except using print(" ") to make empty line for cleaner display, are there any others options.?
If I want to do something like if my_answer == "Y" OR "y"*, what kind of command i could use for OR?
How can I make my font size bigger when I do comment in the community?
Do you guys think Python should be someones first coding language?
Any of you tried the Techdegree thing? If Yes, Please tell me more about it.
My GitHub: https://github.com/r37r0uv33/Python/blob/master/robotnum.py
Have Fun!
import random
import time # Tools import.
def play_again():
again = input("Play again? (Y/N) :")
if again == "Y":
print(" ")
print("Loading...")
time_sleep(2)
start_game()
else:
print(" ")
print("Thank You for Playing! by: Jackson Lai (r37rouv33)")
print(" ")
raise SystemExit() # I was using (break) in here and I've got an error called "break outside loop".
# After some Googling I found that (break) just can apply on (for) or (while). hahaha I am such a noob.
def start_game():
print('***************** "Human VS Computer" Number Guessing Game *****************') # Some greetings and setup for the player.
print(" ") # I am wondering are there any method to make them nice and clean? except puting print(" ")
print("HELLO HUMAN!")
print(" ")
time.sleep(1)
print("Before we start the game, you have to set up few rules...")
print(" ")
try:
a = int(input("What is the lowest range you would like me to guess? : ")) # I would like the player set up there own range and life chance.
print(" ")
b = int(input("What is the highest range you would like me to guess? : "))
print(" ")
guess_chance = int(input("How many chances would you like to give me? : ")) # In here you could use negative numbers too :DDD
except ValueError:
print(" ")
print("############ Your input is not an integer... Please don't this again! ############")
print(" ")
print("Game Restart....")
print(" ")
time.sleep(2)
start_game()
else:
print(" ")
print("PLEASE BE FOCUS ON THE NUMBER YOU PICKED... I AM GOING INTO YOUR MIND...")
time.sleep(2)
print(" ")
computer_guess = random.randint(a, b)
while guess_chance > 0:
print("Loading....")
print(" ")
time.sleep(2)
print("UHHMMM....MAYBE IT IS {} ?".format(computer_guess))
print(" ")
time.sleep(1)
print("AM I RIGHT? (attempt remain: {})".format(guess_chance))
print(" ")
print("If I am correct type (Y)")
print("If the number is higher than my guess type (H), if it's lower, type (L)")
print(" ")
my_answer = input("Your answers is? >>>> ")
print(" ")
if my_answer == "Y":
print("HAHHAHAHHA...I WON THE GAME!! I COULD READ YOUR MIND!!!!")
print(" ")
play_again()
elif my_answer == "H":
a = computer_guess + 1 # In here if the numbers in your mind is higher than what computer guess
guess_chance -= 1 # the lower value in the ramdom.randint will be replace by the guessed number
computer_guess = random.randint(a, b) # And (+1) to the guessed number in here,
print(" ") # if not it's possible to genarate a repeated number in the next guess.
elif my_answer == "L":
b = computer_guess - 1 # For same reason I did the samething here but replace the higher value with (-1)
guess_chance -= 1
computer_guess = random.randint(a, b)
print(" ")
else:
print("######## You answer is not vaild with my instruction. Please don't this again! ########")
print(" ")
time.sleep(2)
continue
print("OUT OF CHANCES!!! HUMAN WON.......")
print(" ")
play_again()
start_game()
1 Answer
Steven Parker
231,261 PointsHere's a few answers:
1. Except using print(" ") to make empty line for cleaner display, are there any others options.?
You can leave off the argument and just write: print()
2. If I want to do something like if my_answer == "Y" OR "y"*, what kind of command i could use for OR?
You can use "or" (lower case) if you have a complete test on both sides, like this:
if my_answer == "Y" or my_answer == "y":
You could also use in with an array:
if my_answer in ["Y", "y"]:
3. How can I make my font size bigger when I do comment in the community?
As shown on the Markdown Basics page, you can create headers with hash marks ("#
"), like I did on my top line here. That line is a level 2 header (it has "##
" at the beginning). I would recommend reserving headers for emphasis, as making every line a header could make your postings seem more annoying than important.
4. Do you guys think Python should be someones first coding language?
I personally consider it an excellent choice as it takes very little time to acquire basic functionality, but it offers many very powerful features if you continue to study it. Another good choice would be JavaScript — it requires a bit more work to reach basic functionality, but it does happen to be the most widely used programming language in the world.
5. Any of you tried the Techdegree thing? If Yes, Please tell me more about it.
I haven't personally, but it seems like it might be a good choice for someone needing to provide proof of accomplishment and/or someone looking for individual supervision and more structure and program pacing than the entirely self-paced study programs provide. Perhaps a Techdegree student might tell us about their experience and the reasons for their choice.
Jackson Lai
3,538 PointsJackson Lai
3,538 PointsThank You !