Skip to content
Snippets Groups Projects
Commit c6970b35 authored by Philipp Gloor's avatar Philipp Gloor
Browse files

Exercise 8, 9, random example

parent 4297e0a4
No related branches found
No related tags found
No related merge requests found
import random
random.seed(12)
target = random.randrange(1, 101)
counter = 1
while True:
guess = int(input("Guess the number: "))
if guess == target:
print("You guessed it!")
break
elif guess < target:
print("Too low!")
else:
print("Too high!")
counter += 1
print(f"You guessed {counter} times.")
import random
target = int(input("Define the number that the algorithm has to guess: "))
start = 1
end = 101
counter = 1
while True:
guess = random.randrange(start, end)
if guess == target:
print("Random number found!")
break
if guess > target:
end = guess
if guess < target:
start = guess + 1
counter += 1
print(f"It took {counter} tries")
import random
random.seed(12)
for _ in range(10):
print(random.randrange(1, 101))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment