Old pc simulator
Tags: old, pc
Published: 2023-08-05 17:07:37

This program will allow you to simulate an old pc interface and this is not also that big and it also have functioning commands
But with some my own preferences 
```python
from random import randint as intt, choice as chose

def start():
    def do(amount,to):
        amount = int(float(amount))
        if not amount > 250 and amount < 1:
            to += amount
            return to
        else:
            print(f.RED + "LocalAmountError: Error invalid amount")
    mem_inc = False
    r = 5002
    mem = {
    }
    chart = {
    "1 Ray": "1 KB/1024 Bytes",
    "1 KRay": "1 MB",
    "1 GRay": "512 MB"
    }
    from colorama import Fore as f, Style as s,Back as b
    
    print(f.YELLOW + "Note: Displaying a text also takes memory")
    print(f.YELLOW + "You currently have 5 krays/MB of mem")
    print(s.RESET_ALL)
    while True:
        print(f.CYAN, s.BRIGHT)
        print("Your computer's memory is:")
        for key,val in mem.items():
            print(f"{f.LIGHTBLACK_EX}NAME: {key}\n  VALUE: {val}\n{f.RESET}{f.CYAN}")
        keys = [
        "display [text]",
        "solve [problem]",
        "clear",
        "save & close",
        "Type",
        "start text1",
        "start guess game",
        "remove file [file name]",
        "install mem inc",
        "start genz",
        "show chart"
        ]
        apps = {
        
        }
        print("Enter a key (k-help): ")
        key = input(f.LIGHTGREEN_EX + s.BRIGHT)
        
        if key.lower() == "k":
            print()
            [print(this_key) for this_key in keys]
            print()
        elif key.lower() == "show chart":
            for ray, val in chart.items():
                print(f"{f.WHITE}{ray} = {val}{f.RESET}")
        elif key.lower() == "install mem inc":
            mem_inc = True
        elif key.lower() == "start mem inc":
            if mem_inc:
                r = do(input("Enter amount of storage: "),r)
            else:
                print(f.RED + "LocalAppError: App mem inc not installed"+ f.RESET)
        elif key.startswith("remove file "):
            try:
                import os
                os.remove(key.replace("remove file ","",1))
            except Exception as e :
                print(f.RED + "LocalError: "+str(e),s.RESET_ALL)
        elif key.lower() == "type":
            tn = input("Type name: ")
            tv = input("Type value: ")
            mem[tn] = tv
        elif key.startswith("display "):
            text = key.replace("display ","",1)
            print(text)
            mem[f"STRING {text}"] = text
        elif key.startswith("solve "):
            prob = key.replace("solve ","",1)
            if "+" in prob:
                n1,n2 = prob.split(" + ")
                n1,n2 = float(n1),float(n2)
                sum = n1 + n2
                print(f"{n1} + {n2} = {sum}")
                mem[f"SUM OF {n1} + {n2}"] = sum
            elif "-" in prob:
                n1,n2 = prob.split(" - ")
                n1 = float(n1)
                n2 = float(n2)
                diff = n1 - n2
                print(f"{n1} - {n2} = {diff}")
                mem[f"DIFF OF {n1} - {n2}"] = diff
            elif "*" in prob:
                n1,n2 = prob.split(" * ")
                n1 = float(n1)
                n2 = float(n2)
                prod = n1 * n2
                print(f"{n1} * {n2} = {prod}")
                mem[f"PRODUCT OF {n1} * {n2}"] = prod
            elif "/" in prob:
                n1,n2 = prob.split(" / ")
                n1 = float(n1)
                n2 = float(n2)
                div = n1 / n2
                print(f"{n1} / {n2} = {div}")
                mem[f"DIVISION OF {n1} / {n2}"] = div
            else:
                print(f.RED + "SolveError: Error invalid equation '"+prob+"'",s.RESET_ALL)
        
        elif key.lower() == "refresh":
            mem = {}
        elif key == "start text1":
            print("Welcome, E- exit")
            print(f.YELLOW + "Warning: This dont supports line editing\nAnd syntax highlighting",s.RESET_ALL)
            num = 0
            lines = []
            while True:
                num += 1
                ln = input(f"{num} ")
                if ln.lower() == "e":
                    try:
                        with open(input("File name: "),"x") as f:
                            for l in lines:
                                f.write(l + "\n")
                            
                    except Exception as e:
                        print(f.RED + "LocalError: "+str(e),s.RESET_ALL)
                    break
                else:
                    lines.append(ln)
        elif key.startswith("load "):
            fn = key.replace("load ","",1)
            try:
                memo = open(fn).read()
                memo = str(memo)
                m = memo.split("\n")
                mem = {}
                m[-1] = "TypeError, Invalid type ''"
                for l in m:
                    #if l == "":
#                        pass
#                    else:
                    ln = l.split(", ")
                    mem[ln[0]] = ln[1]
                
            except FileNotFoundError:
                print(f.RED + "FileError: No file for "+fn,s.RESET_ALL)
                
        elif key.lower() == "save & close":
            fn = input("Enter file name: ")
            try:
                with open(fn,"x") as f:
                    for key,v in mem.items():
                        f.write(f"{key}, {v}" + "\n")
                        
                
            except Exception as e:
                import os
                #fn = input("Enter file name: ")
                os.remove(fn)
                os.remove("matrix")
                with open(fn,"x") as f:
                    for key,v in mem.items():
                        f.write(f"{key}, {v}" + "\n")
                
           # matrix[njj] = 0
            print(s.RESET_ALL)
            break
        elif key.startswith("start guess game"):
            l = key.replace("start guess game","",1)
            num = intt(0,10)
            score = 0
            while True:
                print(f"score: {score}")
                guess = input("Guess the number(78-exit) ")
                guess = float(guess)
                guess = int(guess)
                if guess == num and guess != 78:
                    num = intt(0,10)
                    print("Correct!")
                    score += 1
                elif guess != num and guess != 78:
                    print("Wrong! Guess it again")
                if guess == 78:
                    mem["SCORE OF GUESS GAME"] = score
                    
                    break
        elif key.lower().startswith("start genz"):
            print(f.YELLOW + "Tip: run to run and close/e to exit", f.RESET)
            num = 0
            lines = []
            while True:
                num += 1
                line = input(f"{num} ")
                if line.lower() == "run":
                    break
                elif line == "e":
                    fn = input("Enter file name: ")
                    if fn.endswith(".gz"):
                        try:
                            with open(fn,"x") as f:
                                for l in lines:
                                    f.write(l+"\n")
                        except Exception as e:
                            print(f.RED + "Error: "+str(e), f.RESET)
                    else:
                        try:
                            with open(fn + ".gz","x") as f:
                                for l in lines:
                                    f.write(l+"\n")
                        except Exception as e:
                            print(f.RED + "Error: "+str(e), f.RESET)
                            
                else:
                    lines.append(line)
            for l in lines:
                if l.startswith("disp "):
                    print(l[5:])
                elif l.startswith("solve "):
                    try:
                        print(eval(l[6:]))
                    except Exception as e:
                        print(f.RED + "Error: "+str(e), f.RESET)
                elif l.startswith("//") or l == "" or l.startswith(" "):
                    pass
                
                else:
                    print(f.RED + "LocalCodeError: No keywords for "+l, f.RESET)
            fn = input("Enter file name: ")
            if fn.endswith(".gz"):
                try:
                    with open(fn,"x") as fi:
                        for l in lines:
                            fi.write(l+"\n")
                except Exception as e:
                        print(f.RED + "Error: "+str(e), f.RESET)
            else:
                try:
                    with open(fn + ".gz","x") as fi:
                        for l in lines:
                            fi.write(l+"\n")
                except Exception as e:
                    print(f.RED + "Error: "+str(e), f.RESET)
        
        if len(mem) > r:
            print("Your computer memory is full")
            f = input("Restart? y/n: ")
            if f == "y":
                import os
                os.system("clear")
                start()
            else:
                print(s.RESET_ALL)
                break
       # print(s.RESET_ALL)
       
start() 
```