#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Marvin with a simple menu to start up with.
Marvin doesnt do anything, just presents a menu with some choices.
You should add functinoality to Marvin.
"""

marvin_image = r"""
         _
        [ ]
       (   )
        |>|
     __/===\__
    //| o=o |\\
  <]  | o=o |  [>
      \=====/
     / / | \ \
    <_________>
"""

"""
Its an eternal loop, until q is pressed.
It should check the choice done by the user and call a appropriate
function.
"""
while True:
    print(chr(27) + "[2J" + chr(27) + "[;H")
    print(marvin_image)
    print("Hi, I'm Marvin. I know it all. What can I do you for?")
    print("1) Present yourself to Marvin.")
    print("2) Celcius to Farenheit.")
    print("3) Wordmultiplier.")
    print("4) Sum and average.")
    print("5) Comparison.")
    print("6) Character addition.")
    print("7) Isogram.")
    print("A1) String check.")
    print("q) Quit.")

    choice = input("--> ")

    if choice == "q":
        print("Bye, bye - and welcome back anytime!")
        break

    elif choice == "1":
        name = input("What is your name? ")
        print("\nMarvin says:\n")
        print("Hello %s, don't drink an code." % name)
        print("What can I do you for?!")

    elif choice == "2":
        temp = input("Degrees celcius: ")

        print("\nMarvin says:\n")
        try:
            temp = int(temp)
            fahr = temp * 9 / 5 + 32
            print("The temperature in Fahrenheit is: %s." % str(fahr))
        except ValueError:
            print("The submitted value is not an integer.")
    
    elif choice == "3":
        word = input("Submit a word: ")
        mult = input("Multiplier: ")

        print("\nMarvin says:\n")
        try:
            mult = int(mult)

            i = 0
            while (i < mult):
                print(word)
                i += 1
        except ValueError:
            print("Submitted multiplier is not an integer.")

    elif choice == "4":
        numbers = 0
        res = 0
        success = True
        
        while True:
            val = input("Next: ")

            if val == "done":
                break

            try:
                val = int(val)
                numbers += 1
                res += val
            except ValueError:
                print("\nMarvin says:\n")
                print("The submitted value is not an integer.")
                success = False
                break
        
        if success:
            avg = res / numbers
            print("\nMarvin says:\n")
            print("Sum: " + str(res) + " Avg: " + str(avg))

    elif choice == "5":
        last = 0
        
        while True:
            val = input("Next: ")

            if val == "done":
                break

            try:
                val = int(val)

                res = ""
                if val < last:
                    res = "smaller than"
                elif val == last:
                    res = "equal to"
                elif val > last:
                    res = "greater than"
                
                last = val

                print("\nMarvin says:\n")
                print("The number is %s the last number." % res)
            except ValueError:
                print("\nMarvin says:\n")
                print("The submitted value is not an integer.")
                break

    elif choice == "6":
        word = input("Enter a word: ")

        reps = 1
        res = ""

        for letter in word:
            r = 0

            if reps > 1:
                res += "-"

            while r < reps:
                res += letter
                r += 1

            reps += 1

        print("\nMarvin says:\n")
        print(res)

    elif choice == "7":
        word = input("Enter a word: ")

        letters = ""
        res = "match"

        for letter in word:
            if letter in letters:
                res = "no match"
                break
            letters += letter
        
        print("\nMarvin says:\n")
        print(res)

    elif choice == "A1":
        first = input("String to check: ")
        second = input("Look for: ")

        res = "match"

        for lookup in second:
            if lookup not in first:
                res = "no match"

        print("\nMarvin says:\n")
        print(res)

    else:
        print("That is not a valid choice. You can only choose from the menu.")

    input("\nPress enter to continue...")
