Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,496 members, 7,958,504 topics. Date: Wednesday, 25 September 2024 at 03:59 PM |
Nairaland Forum / Science/Technology / Programming / Help With This Python Algorithm.... (1306 Views)
Python Masters, Kindly Help Me Rectify This Python Problem. / Please Review This Python Blog By A Nigerian. / Pls Programmers Help With Similarities Of Pseudocode & Algorithm (2) (3) (4)
Help With This Python Algorithm.... by emilykel(m): 10:59am On Sep 26, 2015 |
hello guys and my fellow python gurus.. I wrote this simple guess game in python using a while loop and random module... the game asks you to guess what it's thinking of then you enter the number,however when you make a wrong guess, it picks another random number.. the issue is, since I wrote it, Av won only about 3 times out of about 300 guesses..I want you guys to bring ideas on how to make the game more winnable because the chances of making a guess are only 20... #-*-coding:utf8;-*- #qpy:3 #qpy:console import random print ("" print("this is a guessing game,you have [ 20 ] attempts" print("this is v.3 in attempt to make the game easy.. " print("" print(" LETS PLAY THE GAME" print ("" number=random.choice(range(1,150)) Max = 150 minn =1 failed = 0 left = 20 while True: guess=input("GUESS THE NUMBER AM THINKING OF/>> " if guess.isalpha(): print (" sorry,you must enter a digit " print("" else: if int(guess) == number: print("" print("###################################" print("# CONGRATULATIONS #" print("# YOU WON #" print("###################################" break elif int(guess) > Max: print ("your guess is a bit too high...." print("" elif int(guess) < minn: print (" your guess is a little too low..." print("" elif failed == 20: print (" you have exhausted your chances..." print("" print ("##################################" print ("# GAME OVER #" print("##################################" print("" print(" [ game by VITRIOL ] " break elif left==1: print("wrong guess, try again .. " failed+=1 left-=1 print("your last attempt... " print("" else: print("wrong guess, try again .. " failed+=1 left-=1 print (left," attempt(s) left.." print ("" this is the python code..
|
Re: Help With This Python Algorithm.... by KelvinMega(m): 1:28pm On Sep 26, 2015 |
reduce the range of the numbers. the probability of guessing a number between 1 and150 is quite low.(1- 30 should be fairly easy) then you should tell your players the range to guess from |
Re: Help With This Python Algorithm.... by emilykel(m): 2:12pm On Sep 26, 2015 |
I know, but I don't wanna reduce the range, am thinking about making 4 picks from behind the scenes so that each guess is checked against the picks for at least a win |
Re: Help With This Python Algorithm.... by Nobody: 5:35pm On Sep 26, 2015 |
emilykel: you either reduce the range or you increase the no of failed attempts. Why did you use Random instead of importing randint from Random, since you are using random integers Also i think you should have used while guess != 0 |
Re: Help With This Python Algorithm.... by emilykel(m): 6:23pm On Sep 26, 2015 |
randint() and random.choice(range()) are the same, besides Av used randint before... I also see no reason to use while guess!=0 |
Re: Help With This Python Algorithm.... by Greatfes17: 11:31pm On Sep 27, 2015 |
You may try allowing the user enter more than one number and then check if any if them matches the guess. I have also similar game written some months back but the guess is between 1 to 20. I don't know how the [code] tag works here so i recommend uploading the file you need help on some other time. my opinion though |
Re: Help With This Python Algorithm.... by Austinoski(m): 11:57pm On Sep 28, 2015 |
use a "for" loop and a list to get four or more random numbers from the Computer and then check the players answer to see if it matches any of those numbers in the list, if true then the player won guess_list = [] for i in range(4): guess = random.randrange(1,1150) guess_list.append(guess) answer = int(raw_input("Enter Guessed number") if (answer in guess_list): player won else: player lost |
Re: Help With This Python Algorithm.... by silento(m): 12:30am On Sep 29, 2015 |
this is a thing I did while am new to python solution.... decide random number outside the while loop ex: number = random.choice(range(200)) run = 0 while run !=0: code ... if choice > number : print number is lower if choice is < number : print number is. higher if choice == number: print yes run = 1 |
Re: Help With This Python Algorithm.... by matthew80(m): 9:42am On Sep 30, 2015 |
Even in real life, a guess out of 150 is too slim, let alone in computing. Dunno why you're sticking to that range though. Meanwhile, you can allow players to input 4 or 5 numbers and check if any matches, or let the computer think of 4 to 5 numbers and check if the single input matches any. |
Re: Help With This Python Algorithm.... by sleepingdemon: 2:44pm On Sep 30, 2015 |
basbone: |
(1) (Reply)
Got A Job For An Astute Web Developer / Lagos State To Train One Million Lagosians On Computer Programming / Anyone Using Ionicframework Professionally? Whats Been Your Experience?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 40 |