Weird behaviour when running the script
<p>I started to code a guess the number type of game. When I execute the program, it either flows perfectly, either doesn't work...</p>

<pre><code>import random
from random import randint

print("Welcome to guess the number!\nDo you want to play the game?")

question = input("")

if question == "Yes".lower():
print("Sweet! Let`s begin!\nGuess the number between 1 and 10!")

    number = random.randint(1, 10)
    guess = int(input("Take a guess!\n"))

    if guess &gt; number:
        print("Your guess is too high")
        guess = int(input("Take a guess!\n"))

    if guess &lt; number:
        print("Your guess is too low")
        guess = int(input("Take a guess!\n"))

    if guess == number:
        print("Your guess was correct!")

elif question == "No".lower():
    print("Too bad! Bye!")
    quit()
</code></pre>

<p>I absolutely no idea whether it happens because of the code, or pycharm is to blame! </p>

<p>You really need a while loop. If the first guess is too high then you get another chance, but it then only tests to see if it is too low or equal. If your guess is too low then your second chance has to be correct.</p>

<p>So you don't need to keep testing, you can simplify, but you should really do this at the design stage.  Here is my version:</p>

<pre><code>import random
#  from random import randint   &lt;&lt; no need for this line

print("Welcome to guess the number!")

question = input("Do you want to play the game? ")

if question.lower() == "yes":
    print("Sweet! Let`s begin!\nGuess the number between 1 and 10!")

    number = random.randint(1, 10)
    guess = None                     # This initialises the variable

    while guess != number:           # This allows continual guesses

        guess = int(input("Take a guess!: ")) # Only need one of these

        if guess &gt; number:
            print("Your guess is too high")
        elif guess &lt; number:     
            print("Your guess is too low")
        else:   # if it isn't &lt; or &gt; then it must be equal!
            print("Your guess was correct!")

else:
    # why do another test?  No need.
    print("Too bad! Bye!")

    # No need for quit - program will exit anyway
    # but you should not use quit() in a program
    # use sys.exit() instead
</code></pre>

<p>Now I suggest you add a count of the number of guesses the player has before they get it right, and print that at the end!</p>

<p>Edit:  You will note that my <code>import</code> statement differs from that given by @Denis Ismailaj.  We both agree that only one <code>import</code> is required, but hold different opinions as to which one.  In my version I <code>import random</code>, this means that you have to say <code>random.randint</code> whereas in the other you only say <code>randint</code>.</p>

<p>In a small program there isn't much to choose between them, but programs never get smaller.  A larger program, which could easily be importing 6,7,8 or more modules, it is sometimes difficult to track-down which module a function comes from - this is known as <em>namespace pollution</em>.  There will be no confusion with a well-known function like <code>randint</code>, and if you explicitly give the name of the function then it can easily be tracked back.  It is only a question of personal preference and style.</p>

<p>With number of guesses added:</p>

<pre><code>import random

print("Welcome to guess the number!")

question = input("Do you want to play the game? ")

if question.lower() == "yes":
    print("Sweet! Let`s begin!\nGuess the number between 1 and 10!")

    number = random.randint(1, 10)
    guess = None
    nrGuesses = 0                    # Added

    # Allow for continual guesses
    while guess != number and nrGuesses &lt; 6:    # Changed

        guess = int(input("Take a guess!: ")) # Only need one of these

        nrGuesses += 1               # Added

        if guess &gt; number:
            print("Your guess is too high")
        elif guess &lt; number:
            print("Your guess is too low")
        else:   # if it isn't &lt; or &gt; then it must be equal!
            print("Your guess was correct!")

else:
    print("Too bad! Bye!")

print("Number of guesses:", nrGuesses) # Added
</code></pre>

python pycharm