def candidate_input(candidates): """ Presents the list of candidates, asks user to vote until done, prints the results of the voting. :param candidates: dict :return: """ options = {index: goof for index, goof in enumerate(candidates, start=1)} while True: display_ballot(candidates) i_choose = input( "Enter your choice for President or type 'done' to see the results. ➙ " ) try: i_choose = int(i_choose) except ValueError: if i_choose == 'done': chalk.cyan(f"Total votes per candidate: {candidates}") winner = max(candidates.items(), key=lambda t: t[-1]) chalk.magenta( f"The winner is {winner[0]} with {winner[1]} votes.") break chalk.red('Please enter the number to the left of the name.') continue if input_is_valid(i_choose): choice = options[i_choose] candidates[choice] += 1
def print_image(file_name): with open(file_name) as image: for line in image: line = line.strip('\n') print(chalk.magenta(line)) input(chalk.blue('Press any key to continue...')) return
def print_image(file_name): with open(file_name, 'r') as image: lines = [line.rstrip() for line in image] for line in lines: print(chalk.magenta(line)) time.sleep(2) return
def another_trans(account: act) -> None: chalk.green(""" Would you like another transaction? =====*=====*=====*=====*=====*=====*===== Yes: press 1 No: press 2 """) choose = int(input('Enter ➤➤ ')) if choose == 1: dep_with(account=account) else: chalk.magenta("Thank you! Have a nice day.") quit()
def print_image(file_name): file_name = 'adventure_game/' + file_name with open(file_name, 'r') as image: lines = [line.rstrip() for line in image] audio = lines.pop(0) for line in lines: print(chalk.magenta(line)) time.sleep(2) return
def welcome(balance: int, account_type: str) -> None: """ Greet customer, open deposit and accept first deposit. :return: """ account = None while True: chalk.green(""" Welcome to Uptown Bank. ======*======*======*======*====== Open Account press 1 To quit press 2 """) choose = int(input('Enter ➤➤ ')) if choose == 1: chalk.green(f"Make your account number, enter any four numbers.") choice = int(input('Enter ➤➤ ')) # except ValueError: # chalk.red('Please enter a number.') account = Account(balance, account_type) chalk.green(f"Enter the amount to deposit.") new_dep = int(input('➤➤ $ ')) new_deposit = account.deposit(new_dep) current_balance = account.get_funds() chalk.magenta(f"""\n${new_deposit} has been deposited into your account. Your current balance is {current_balance}.""") another_trans(account=account) else: choose == 2 chalk.magenta("Maybe next time. Chiao!") quit()
def main() -> None: args: Namespace = get_args() # start main script print(chalk.green('Distinct Happy Number Range Counter\n')) print('Range:', chalk.red(args.r)) time_start: float = perf_counter() # start timer count: int = get_dist_happy(args.r) time_end: float = perf_counter() # end timer time_delta: float = time_end - time_start print('Count Total: {count}'.format(count=chalk.cyan(count))) print('Calc Time (s): {}'.format(chalk.magenta(format_dec(time_delta))))
def voting_machine(nominees): options = {index: cand for index, cand in enumerate(nominees, start=1)} votes = nominees try: vote_cast = int( input('Type the number for the candidate you want. --> ')) except ValueError: chalk.red('Not valid! Try again') return voting_machine(nominees) choice = options[vote_cast] votes[choice] += 1 chalk.green("Your vote has been counted.") chalk.yellow(f"Current standing: {votes}") more_votes = input("Continue voting? Y/n ") if more_votes.lower() != 'n': voting_machine(nominees) else: winner = max(votes.items(), key=lambda t: t[-1]) chalk.magenta(f"The winner is {winner[0]} with {winner[1]} votes.")
def wrapper_welcome(): ascii_art_1 = """ _____ _ _ |_ _(_)_ __ ___ ___ ___ ___ __ _| | ___ | | | | '_ ` _ \ / _ \ / __|/ __/ _` | |/ _ \\ | | | | | | | | | __/ \__ | (_| (_| | | __/ |_| |_|_| |_| |_|\___| |___/\___\__,_|_|\___|""" ascii_art_2 = """ ,--,--' . `- | . ,-,-. ,-. ,-. ,-. ,-. | ,-. , | | | | | |-' `-. | ,-| | |-' `-' ' ' ' ' `-' `-' `-' `-^ `' `-'""" message = "The timescalecalculus python library." star = emoji.emojize(':star:', use_aliases=True) print(chalk.green(ascii_art_1, bold = True)) print(chalk.yellow(ascii_art_2, bold = True)) print(chalk.magenta(3*star + " " + message + 3*star)) print(chalk.cyan("¡Bienvenido matemático!")) func()
@contact: [email protected] @date 2015-05-09 23:29 """ import os import sys currentPath = os.path.normpath(os.path.dirname(os.path.realpath(__file__))) rootPath = os.path.normpath(os.path.dirname(currentPath)) sys.path.insert(0, rootPath) import chalk print "%s %s %s %s %s %s %s" % ( chalk.bold("bold"), chalk.dim("dim"), chalk.italic("italic"), chalk.underline("underline"), chalk.inverse("inverse"), chalk.strikethrough("strikethrough"), chalk.black(chalk.gray("black")), ) print "%s %s %s %s %s %s %s %s" % ( chalk.red("red"), chalk.green("green"), chalk.yellow("yellow"), chalk.blue("blue"), chalk.magenta("magenta"), chalk.cyan("cyan"), chalk.white("white"), chalk.gray("gray")) print "%s %s %s %s %s %s %s" % ( chalk.bgRed("bgRed"), chalk.bgGreen("bgGreen"), chalk.bgYellow("bgYellow"), chalk.bgBlue("bgBlue"), chalk.bgMagenta("bgMagenta"), chalk.bgCyan("bgCyan"), chalk.bgWhite("bgWhite"))
def score_ari(score: int, text_file: str) -> None: ari_scale = { 1: { 'ages': '5-6', 'grade_level': 'Kindergarten' }, 2: { 'ages': '6-7', 'grade_level': '1st Grade' }, 3: { 'ages': '7-8', 'grade_level': '2nd Grade' }, 4: { 'ages': '8-9', 'grade_level': '3rd Grade' }, 5: { 'ages': '9-10', 'grade_level': '4th Grade' }, 6: { 'ages': '10-11', 'grade_level': '5th Grade' }, 7: { 'ages': '11-12', 'grade_level': '6th Grade' }, 8: { 'ages': '12-13', 'grade_level': '7th Grade' }, 9: { 'ages': '13-14', 'grade_level': '8th Grade' }, 10: { 'ages': '14-15', 'grade_level': '9th Grade' }, 11: { 'ages': '15-16', 'grade_level': '10th Grade' }, 12: { 'ages': '16-17', 'grade_level': '11th Grade' }, 13: { 'ages': '17-18', 'grade_level': '12th Grade' }, 14: { 'ages': '18-22', 'grade_level': 'College' } } score_data = ari_scale.get(score, ari_scale[14]) chalk.magenta(f""" -------------------------------------------------------- The ARI for the file, {text_file}, is {score}. This corresponds to a {score_data['grade_level']} level of difficulty that is suitable for an average person {score_data['ages']} years old. -------------------------------------------------------- """)
with open("cache/hubs.json") as f: hubs = json.loads(f.read()) else: print(chalk.green("Gathering hubs list...")) hubs = gatherHubList() print(chalk.green("Saving to cache")) with open("cache/hubs.json", "w") as f: f.write(json.dumps(hubs)) print() print() print("Found", len(hubs), "hubs:") for hub in hubs: print("#{}{}{}{}".format(chalk.yellow(hub["id"].ljust(30)), chalk.green(str(hub["subscribers"]).ljust(10)), chalk.magenta(str(hub["rating"]).ljust(10)), hub["name"])) print() print() if os.path.exists("cache/gathered_posts.json"): print(chalk.green("Getting gathered posts list from cache")) with open("cache/gathered_posts.json") as f: gathered_posts = set(json.loads(f.read())) else: gathered_posts = set() if os.path.exists("cache/gathered_hubs.json"): print(chalk.green("Getting gathered hubs list from cache")) with open("cache/gathered_hubs.json") as f: gathered_hubs = json.loads(f.read())
def tip(*data): print(chalk.magenta("tip"), " ".join(data))
#!/usr/bin/env python import chalk chalk.blue("Hello world!!") chalk.yellow("Listen to me!!!") chalk.red("ERROR", pipe=chalk.stderr) chalk.magenta('This is pretty cool', opts='bold') chalk.cyan('...more stuff', opts=('bold', 'underscore'))
def dep_with(account: act) -> int: # parameters work with welcome() while True: chalk.green(""" What would you like to do? =====*=====*=====*=====*=====*=====*=====*=====*=====*===== Deposit to checking: press 1 ➤ Deposit to savings: press 2 ➤ Withdrawal from checking: press 3 ➤ Withdrawal from savings: press 4 ➤ """) choose = int(input('Enter ➤➤ ')) if choose == 1: chalk.magenta("Enter deposit amount:") # Deposit to checking new_dep = int(input('➤➤ ')) # except ValueError: # pass dep_amount = account.deposit(new_dep) new_balance = account.get_funds() chalk.magenta(f"""{dep_amount} has been deposited to your account. Your new balance is {new_balance}.""") elif choose == 2: chalk.magenta("Enter deposit amount:") # Deposit to savings new_svgs_dep = int(input('➤➤ ')) svgs_dep_amount = account.deposit(new_svgs_dep) svgs_new_balance = account.get_funds() chalk.magenta(f"""{svgs_dep_amount} has been deposited to your account. Your new balance is {svgs_new_balance}.""") elif choose == 3: chalk.magenta("Enter withdrawal amount:") # Withdrawal from checking new_withdra = int(input('➤➤ ')) account.withdrawal(new_withdra) new_balance = account.get_funds() chalk.magenta(f"""{new_withdra} has been withdrawn from your account. Your new balance is {new_balance}.""") elif choose == 4: chalk.magenta("Enter withdrawal amount:") # Withdrawal from savings svgs_new_withdra = int(input('➤➤ ')) account.withdrawal(svgs_new_withdra) svgs_new_balance = account.get_funds() chalk.magenta(f"""{svgs_new_withdra} has been withdrawn from your account. Your new balance is {svgs_new_balance}.""") # except ValueError as error: # chalk.red(error.args[0]) return another_trans(account=account) # how affect svgs_account