Python Forum
Need help with fixing iteration counter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with fixing iteration counter
#1
Probably a brainlet question, but I will ask anyway since I'm too lazy to actually read the documentation.
I've been trying to do this exercise: https://www.practicepython.org/exercise/...e-one.html

Basically : Generate a random number between 1 and 9 (including 1 and 9). Ask the user to guess the number, then tell them whether they guessed too low, too high, or exactly right.

Now this works proper, but I've decided to also add a counter that counts every guess the user takes and display it at the end...But I screwed up, and I have no idea why Wall , as this usually works in languages like C#.
The code:

"""17.10.18
guessing game one
generates a random number between 1 and 9 (including 1 and 9)
then asks the user to guess a number to see how close it is to the solution
"""

#importing modules
import random

#declaring variables
rnd = random.randint(1, 9)
num = 0
count = 1
#user input
while num != rnd:
    num = input("Guess a number between 1 & 9: ")

    if num != rnd and num < rnd:
        print("Too small, try again...")
        count++

    elif num != rnd and num > rnd:
        print("Too large, try again...") 
        count++

print("Good job! it took you " + count + " guesses to win.")
quit()
Any help is appreciated Dance !
Reply


Messages In This Thread
Need help with fixing iteration counter - by Kapolt - Oct-17-2018, 09:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  fixing error TypeError: 'float' object is not subscriptable programmingirl 1 1,548 Jan-28-2023, 08:13 PM
Last Post: deanhystad
  Need help fixing Index Error adesimone 1 1,326 Nov-21-2022, 07:03 PM
Last Post: deanhystad
  Fixing my backup function Beginner_coder123 4 3,070 Jun-15-2019, 07:56 PM
Last Post: Beginner_coder123
  Fixing arrays output in Python WLST script pkbash 2 4,027 Feb-28-2019, 06:20 PM
Last Post: pkbash
  i need help in fixing my scientific calculator coding : (, im using python 3.5.5 hans77 1 4,192 Oct-17-2018, 03:26 AM
Last Post: stullis

Forum Jump:

User Panel Messages

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