import random

def figure(n):
    for i in range(1,n + 1):
        print(" " * (n - i), end = "")
        for j in range(1, i * 2):
            print(j, end = "")
        print()

def Opgave4():
    figure(1)
    figure(2)
    figure(3)
    figure(4)
    figure(5)

print("Opgave 4:")
#Opgave4()
print("Opgave 5:")

def giveIntro():
    print("Try to guess my two-digit")
    print("number, and I'll tell you how")
    print("many digits from your guess")
    print("appear in my number.")
    print()

def is_number(s):
    try:
        i = int(s)
        return 0 <= i <= 99
    except ValueError:
        return False

def get_number(prompt):
    s = input(prompt)
    while not is_number(s):
        s = input(prompt)
    return int(s)

def matches(number, guess):
    numMatches = 0
    if guess // 10 == number // 10 or guess // 10 == number % 10:
        numMatches += 1
    if (guess // 10 != guess % 10) and (guess % 10 == number // 10 or guess % 10 == number % 10):
        numMatches += 1
    return numMatches

def Opgave5():
    giveIntro()

    number = random.randint(0,99) # Pick random number between 0 and 99
    print(number)
    guess = get_number("Your guess? ")

    numGuesses = 1

    while (guess != number):
        numMatches = matches(number, guess)
        print(f"Incorrect (hint: {numMatches} digits matches).")
        guess = get_number("Your guess? ")
        numGuesses += 1

    print(f"You got it right in {numGuesses} tries")
Opgave5()
