Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import curses
- ascii_art = r"""
- _____ _ _
- / ____| | | | |
- | (___ ___| |__ ___ ___ | |
- \___ \ / __| '_ \ / _ \ / _ \| |
- ____) | (__| | | | (_) | (_) | |
- |_____/ \___|_| |_|\___/ \___/|_| _
- | | | | | |
- | |__| | ___ _ __ ___ _____ _____ _ __| | __
- | __ |/ _ \| '_ ` _ \ / _ \ \ /\ / / _ \| '__| |/ /
- | | | | (_) | | | | | | __/\ V V / (_) | | | <
- |_| |_|\___/|_| |_| |_|\___| \_/\_/ \___/|_| |_|\_\
- | | | | | |
- | |__| |_ _| |__
- | __ | | | | '_ \
- | | | | |_| | |_) |
- |_| |_|\__,_|_.__(_)
- """
- footer_text = "CALCULATOR - GAMES - HELP"
- additional_ascii_art = r" ,`~─────────────────~,`"
- instruction_text = [
- "Use the hyphen '-' for minus",
- "Use the slash '/' for division",
- "Type 'PI' for pi, 'SQR.R' for square root of typed number"
- ]
- def main(stdscr):
- # Clear screen
- stdscr.clear()
- # Get the screen height and width
- sh, sw = stdscr.getmaxyx()
- # Split the ASCII art into lines
- lines = ascii_art.splitlines()
- # Calculate the starting column to center the ASCII art
- start_col = (sw - max(len(line) for line in lines)) // 2
- # Display each line of the ASCII art at the top center
- for i, line in enumerate(lines):
- stdscr.addstr(i, start_col, line)
- # Calculate the position to display the footer text centered
- footer_row = len(lines) + 2
- footer_col = (sw - len(footer_text)) // 2
- # Display the footer text
- stdscr.addstr(footer_row, footer_col, footer_text)
- # Refresh the screen to display the ASCII art and footer text
- stdscr.refresh()
- while True:
- # Get user input
- curses.echo()
- input_row = footer_row + 6 # Adjusting to make space for additional ASCII and instructions
- input_col = (sw - 20) // 2
- user_input = stdscr.getstr(input_row, input_col, 20).decode('utf-8').strip().lower()
- # Clear the input area
- stdscr.move(input_row, input_col)
- stdscr.clrtoeol()
- if user_input == "calculator":
- # Display the additional ASCII art in place of the input
- stdscr.addstr(footer_row + 2, (sw - len(additional_ascii_art)) // 2, additional_ascii_art)
- # Display the instructions
- for i, instruction in enumerate(instruction_text):
- stdscr.addstr(footer_row + 4 + i, (sw - len(instruction)) // 2, instruction)
- stdscr.refresh()
- else:
- try:
- # Replace 'x' with '*' for multiplication
- user_input = user_input.replace('x', '*')
- # Evaluate the expression and print the result
- result = eval(user_input)
- stdscr.addstr(input_row + 2, (sw - len(str(result))) // 2, str(result))
- stdscr.refresh()
- except Exception as e:
- stdscr.addstr(input_row + 2, (sw - len("Error")) // 2, "Error")
- stdscr.refresh()
- # Wait for user input to exit
- stdscr.getch()
- # Initialize the curses application
- curses.wrapper(main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement