Again is used these Python 3 programming examples. There I found how to use while-loops.
Here is my code:
import random
numCom = random.randrange(1, 101)
numUs = int( input( "Give me a number between 1 and 100: "))
attempt = int(1)
while numCom != numUs :
attempt = attempt + 1
if (numCom < numUs) :
print( "My number is smaller.")
numUs = int( input( "Give me a another number: "))
else :
print ( "My number is greater.")
numUs = int( input( "Give me a another number: "))
print(numCom,"was the right number!")
print("You needed",attempt,"attempts.")
WSQ06 – Pick a Number by finntec is licensed under a Creative Commons Attribution 4.0 International License.