Python Forum
The count variable is giving me a hard time in this code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The count variable is giving me a hard time in this code
#1
from random import randrange

def toohigh():
	# displays too high sequence
	count += 1
	return('Too high! Try again. ')
	guess = input('Guess my number between 1 and 1000. ')
	play()
	
def toolow():
	# displays too low sequence
	count += 1
	return('Too low! Try again. ')
	guess = input('Guess my number between 1 and 1000. ')
	play()

def correct():
	# displays correct sequence
	count += 1
	return('Congrats! That was the correct number!')
	if count <= 10:
		return('It took you ', str(count), 'guesses.' 'You either know the secret or got lucky.')
	if count > 10:
		return('It took you ', str(count), 'guesses.' 'I think you can do better than that.')
	playagain()

def playagain():
	playagain = input('Would you like to play again? y/n ')
	if playagain == 'y':
		play()
		count = 0
	if playagain == 'n':
		return('Bye!')
		count = 0
	else:
		return('Please answer y or n')
		playagain()

def play():
	# plays game
	count = 0
	x = randrange(1000)
	guess = int(input('Guess my number between 1 and 1000. '))
	while guess != x:
		if int(guess) > x:
			toohigh()
		if guess < x:
			toolow()
		if guess == x:
			correct()

play()
# I am 100% a noob, thank you for helping.
Reply


Messages In This Thread
The count variable is giving me a hard time in this code - by D4isyy - Aug-09-2020, 06:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Hard time trying to figure out the difference between two strings carecavoador 2 700 Aug-16-2023, 04:53 PM
Last Post: carecavoador
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,626 Mar-27-2023, 07:38 AM
Last Post: buran
  Row Count and coloumn count Yegor123 4 1,381 Oct-18-2022, 03:52 AM
Last Post: Yegor123
  Assistance with running a few lines of code at an EXACT time nethatar 5 3,326 Feb-24-2021, 10:43 PM
Last Post: nilamo
  Clicker count increase by 1 each time blakefindlay 1 5,752 Feb-03-2021, 03:50 PM
Last Post: deanhystad
  Stumped by my own code (ratio & epoch-time calculation). MvGulik 2 2,175 Dec-30-2020, 12:04 AM
Last Post: MvGulik
  Code giving same output no matter the input. Yort 2 2,599 Dec-20-2020, 05:59 AM
Last Post: buran
  Code taking too much time to process ErPipex 11 5,015 Nov-16-2020, 09:42 AM
Last Post: DeaD_EyE
  What is the run time complexity of this code and please explain? samlee916 2 2,324 Nov-06-2020, 02:37 PM
Last Post: deanhystad
  Having a hard time conceptualizing how to print something MysticLord 6 3,158 Sep-19-2020, 10:43 PM
Last Post: MysticLord

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020