def random_short_form(): """ This one picks a random short form and then runs single_short_form to quiz on it We keep these functions separate so that we can do a primitive review feature in short_form_practice by feeding wrong ones back into single_short_form later """ polarity, eng_pol = pick([(Polarity.NEGATIVE, "NEGATIVE"), (Polarity.POSITIVE, "AFFIRMATIVE")]) tense, eng_tense = pick([(Tense.PAST, "PAST"), (Tense.NONPAST, "NONPAST")]) # Pick the verb verb = "it" while ("(something)" in verb) or (verb[0:2] == "it"): # don't want verbs like "はじまる" verb = pick(verb_list) ja_verb = japanese(verb) vclass = verb_class(verb) return single_short_form(verb, eng_pol, eng_tense, ja_verb, vclass, polarity, tense)
def tai_practice(): (ntype, j_verb, en_verb) = pick([ (nouns.do_able, "する", "to do"), (nouns.study_able, "勉強する", "to study"), (nouns.become_able, "なる", "to become"), (nouns.animals, "飼う", "to own"), (nouns.eat_able, "食べる", "to eat"), (nouns.see_able, "見る", "to see"), (nouns.read_able, "読む", "to read"), (nouns.drink_able, "飲む", "to drink"), (nouns.write_able, "書く", "to write"), (nouns.buy_able, "買う", "to buy"), # (nouns.places_absolute, "行く", "to go"), ]) en_noun = pick(ntype) j_noun = japanese(en_noun) vclass = j_verb_class(j_verb) tai_suffix, en_prefix = pick([ ("たいです", "[I] want"), ("たくないです", "[I] do not want"), ("たかった", "[I] wanted"), ("たくなかった", "[I] didn't want"), ("たがっています", "[Mary] seems to want"), ("たがっていました", "[Mary] seems to have wanted"), ]) # if past: # # If somehting _was_ our plan before, it could have been for # # any time. # en_time = pick(nouns.times_past + nouns.times_future + nouns.times_absolute) # else: # en_time = pick(nouns.times_future + nouns.times_absolute) # j_time = japanese(en_time) j_verb = polite_form(j_verb, vclass, Tense.NONPAST, Polarity.POSITIVE) # Trim off the 「ます」at the end j_verb = j_verb[0:-2] english_prompt = f'Translate "{en_prefix} {en_verb} {en_noun}"' response = f"{j_noun}を{j_verb}{tai_suffix}" try: user_input = input(english_prompt + "\n") # print(f"you said {user_input}") if user_input != response: print(f"{response} is the expected answer\n") return else: print("correct\n") except UnicodeDecodeError: print(f"{response} is the expected answer.\n") pass
async def rpsls(self, ctx, choice: str): """ Play rock, paper, scizzors, lizard, spock. Use `[p]rpsls help` for a diagram.""" choice = choice.lower() if choice == "help": with open(Path(__file__).parent / "info.json") as fp: return await ctx.send(json.load(fp)["diagram"]) if not choice in choices: return await ctx.send("Please enter a valid choice.") b = self.converter(pick(choices)) h = self.converter(choice) k = {0:[1,3],1:[2,4],2:[3,0],3:[4,1],4:[0,2]} if h == b: title = f"{emojis[h]} vs {emojis[b]}" description = f"It's a draw." color = 0x87ceeb elif b in k[h]: title = f"{emojis[h]} vs {emojis[b]}" description = f"You win!" color = 0x22ce70 else: title = f"{emojis[h]} vs {emojis[b]}" description = f"{ctx.me.name} wins." color = 0xff5151 kwargs = {"title": title,"description": description, "color": color} if await ctx.embed_requested(): await ctx.send(embed=discord.Embed(**kwargs)) else: await ctx.send(bold(title) + '\n' + description)
def program_greeter(msg=msg): 'Prints a formatted greeter when starting program' colors = ("red", "green", "yellow", "blue", "magenta", "cyan", "white") color = pick(colors) ascii_art = figlet_format(msg) # formats the message colored_ascii = colored(ascii_art, color) print(colored_ascii)
def random_room(console): generator = RoomGenerator() random_area = pick(generator.areas) mystery_room = Room(console=console, name=generator.gen_name(random_area), desc=generator.gen_desc(random_area)) mystery_room.add_character(character=random_character(console)) return mystery_room
def gen(self): generated_item = Item( name=pick(self.nouns), category='weapon', strength=randrange( 1, 7), # TODO: Scale this to avg level of party and type required_perception=randrange(1, 10)) return generated_item
def practice_all(): while True: practice_func = pick([ qualify_noun, random_short_form, single_ongoing_negative, plan_practice, # become_practice, tai_practice, # n_desu_practice, obligation_practice, ]) practice_func()
def short_form_practice(n): wrong = [] for _ in range(n): response = random_short_form() if response is not None: wrong += [response] while wrong: print(f"{len(wrong)} verbs to review.") review = pick([1, 2, 3]) if review == 1: forgotten_verb = wrong[0] wrong = wrong[1:] response = single_short_form(*forgotten_verb) if response is not None: wrong += [response] else: response = random_short_form() if response is not None: wrong += [response] return
def run_random(tests): test = random.pick(tests) return run_test(test)
def obligation_practice(): particle = "を" (ntype, j_verb, en_verb) = pick([ (nouns.do_able, "する", "to do"), (nouns.study_able, "勉強する", "to study"), (nouns.become_able, "なる", "to become"), # (nouns.animals, "飼う", "to own"), (nouns.eat_able, "食べる", "to eat"), (nouns.see_able, "見る", "to see"), (nouns.read_able, "読む", "to read"), (nouns.drink_able, "飲む", "to drink"), (nouns.write_able, "書く", "to write"), (nouns.buy_able, "買う", "to buy"), (nouns.places_absolute, "行く", "to go"), ]) if j_verb == "行く": particle = "に" en_noun = pick(ntype) j_noun = japanese(en_noun) vclass = j_verb_class(j_verb) in_the_past = pick([True, False]) en_n_desu = "" do_n_desu = pick([True, False]) if do_n_desu: en_n_desu = "(explanation)" n_desu = "" en_time = "" if in_the_past: en_time = pick(nouns.times_past) j_time = japanese(en_time) en_prefix = "[I] had" j_suffixes = [ "ければいけませんでした", "きゃいけませんでした", "くちゃいけませんでした", ] if do_n_desu: j_suffixes = [suffix[:-3] for suffix in j_suffixes] # trim the でした n_desu = "なんでした" else: en_time = pick(nouns.times_future) j_time = japanese(en_time) en_prefix = "[I] have" j_suffixes = [ "ければいけません", "きゃいけません", "くちゃいけません", ] if do_n_desu: n_desu = "なんです" j_verb = plain_form(j_verb, vclass, Tense.NONPAST, Polarity.NEGATIVE) j_verb = j_verb[0:-1] # Trim off the 「い」at the end english_prompt = ( f'Translate "{en_prefix} {en_verb} {en_noun} {en_time} {en_n_desu}"') possible_responses = [ f"{j_time}{j_noun}{particle}{j_verb}{j_suffix}{n_desu}" for j_suffix in j_suffixes ] try: user_input = input(english_prompt + "\n") # print(f"you said {user_input}") if user_input not in possible_responses: print("Any of the following would have been accepted:\n") for response in possible_responses: print(response) return else: print("correct\n") except UnicodeDecodeError: print("Any of the following would have been accepted:\n") for response in possible_responses: print(response) pass
while running: if engine.get_async_key_state(engine.VK_ESCAPE): running = False mixer.stop() break thread(target=check_keys).start() while running: engine.clear() engine.reload_size() engine.reload_geometry() engine.reload_mouse_pos() otnosh_x = engine.window_geometry[2] / engine.width otnosh_y = engine.window_geometry[3] / engine.height engine.shape(engine.fore.GREEN+pick(lister)+engine.style.RESET_ALL, (0, 0), (7, 5)) engine.shape(engine.fore.GREEN+pick(lister)+engine.style.RESET_ALL, (14, 0), (7, 5)) engine.shape(engine.back.RED+pick(lister)+engine.style.RESET_ALL, (0, 10), (21, 5)) engine.text(welcome_text, (int(engine.width/2-len(welcome_text)/2), int(engine.height/2)), start = engine.back.GREEN + engine.fore.BLACK, end = engine.style.RESET_ALL) engine.text(str(engine.mouse_x) + 'x' + str(engine.mouse_y), (int(engine.width/2), engine.height - 1)) try: engine.point('X', (int(engine.mouse_x / otnosh_x), int(engine.mouse_y / otnosh_y))) except: pass engine.up_screen() engine.convert() engine.display() engine.tick(fps) running = False exit()
def plan_practice(): (ntype, j_verb, j_part, en_verb) = pick([ (nouns.do_able, "する", "を", "to do"), (nouns.eat_able, "たべる", "を", "to eat"), (nouns.see_able, "みる", "を", "to see"), (nouns.read_able, "よむ", "を", "to read"), (nouns.drink_able, "のむ", "を", "to drink"), (nouns.write_able, "かく", "を", "to write"), (nouns.buy_able, "かう", "を", "to buy"), (nouns.places_absolute, "いく", "に", "to go"), ]) en_noun = pick(ntype) j_noun = japanese(en_noun) vclass = j_verb_class(j_verb) past, polarity, en_tense, j_tense = pick([ ( True, Polarity.POSITIVE, "I was planning", "つもりでした", ), ( True, Polarity.NEGATIVE, "I was not planning", "つもりでした", ), ( False, Polarity.POSITIVE, "I plan", "つもりです", ), ( False, Polarity.NEGATIVE, "I do not plan", "つもりです", ), ]) if past: # If somehting _was_ our plan before, it could have been for # any time. en_time = pick(nouns.times_past + nouns.times_future + nouns.times_absolute) elif pick([True, True, False]): # Give it some shitty odds en_time = pick(nouns.times_future) else: en_time = pick(nouns.times_absolute) time_part = "" if en_time in nouns.times_absolute: time_part = "に" j_time = japanese(en_time) j_verb = plain_form(j_verb, vclass, Tense.NONPAST, polarity) english_prompt = f'Translate "{en_tense} {en_verb} {en_noun} {en_time}"' response = f"わたしは{j_time}{time_part}{j_noun}{j_part}{j_verb}{j_tense}" try: user_input = input(english_prompt + "\n") # print(f"you said {user_input}") if user_input != response: print(f"{response} is the expected answer\n") return else: print("correct\n") except UnicodeDecodeError: print(f"{response} is the expected answer.\n") pass
def single_ongoing_negative(): # verb = pick(verb_list) particle = "を" (ntype, verb, did, have_already_done, did_not_do, have_not_done) = pick([ ( nouns.do_able, "する", "did", "have already done", "did not do", "have not done", ), ( nouns.eat_able, "食べる", "ate", "have already eaten", "didn't eat", "have not eaten", ), ( nouns.drink_able, "飲む", "drank", "have already drunk", "did not drink", "haven't drunk", ), ( nouns.write_able, "書く", "wrote", "already wrote", "did not write", "haven't written", ), ( nouns.buy_able, "買う", "bought", "already bought", "did not buy", "haven't bought", ), ( nouns.places_absolute, "行く", "went", "already went", "didn't go", "haven't gone", ), ]) if verb == "行く": particle = "に" noun = pick(ntype) # Ok I know this is garbage and I should be handling cases more # intelligently but idk lay off ok tense = pick([1, 2, 3, 4]) if tense == 1: time = pick(nouns.times_past) english_prompt = f"I {did} the {noun} {time}." vclass = j_verb_class(verb) jverb = polite_form(verb, vclass, Tense.PAST, Polarity.POSITIVE) response = f"わたしは{japanese(time)}{japanese(noun)}{particle}{jverb}" elif tense == 2: english_prompt = f"I {have_already_done} the {noun}." vclass = j_verb_class(verb) jverb = polite_form(verb, vclass, Tense.PAST, Polarity.POSITIVE) response = f"わたしはもう{japanese(noun)}{particle}{jverb}" if tense == 3: time = pick(nouns.times_past) english_prompt = f"I {did_not_do} the {noun} {time}." vclass = j_verb_class(verb) jverb = polite_form(verb, vclass, Tense.PAST, Polarity.NEGATIVE) response = f"わたしは{japanese(time)}{japanese(noun)}{particle}{jverb}" elif tense == 4: english_prompt = f"I {have_not_done} the {noun} yet." vclass = j_verb_class(verb) jverb = te_form(verb, vclass) response = f"わたしはまだ{japanese(noun)}{particle}{jverb}いません" try: user_input = input(english_prompt + "\n") # print(f"you said {user_input}") if user_input != response: print(f"{response} is the expected answer\n") return else: print("correct\n") except UnicodeDecodeError: print(f"{response} is the expected answer.\n") pass
def qualify_noun(): """ Qualifying nouns with verbs and adjectives (see: L9, pg. 213-214) """ # The method by which we'll indicate who is the subject of our # sentence. These crrespond to the 4 examples given on page 214. options = ["place", "frequency", "verb", "time"] option = pick(options) # Pick the verb verb = "it" while ("(something)" in verb) or (verb[0:2] == "it"): # don't want verbs like "はじまる" verb = pick(verb_list) ja_verb = japanese(verb) vclass = verb_class(verb) if option == "place": en_verb = verb_to_verbing(verb) # make it into the "ing" form ja_te_verb = te_form(ja_verb, vclass) english_prompt = f"The person who is [{en_verb}] over there" response = f"あそこで{ja_te_verb}いる人" elif option == "frequency": freq = pick(nouns.frequency) # Get a frequency word jfreq = japanese(freq) # Convert it to japanese too en_verb = verb[3:] # remove the leading "to " english_prompt = f"People who [{en_verb}] {freq}" response = f"{jfreq}{ja_verb}人" elif option == "verb": (polarity, eng_pol) = pick([(Polarity.POSITIVE, ""), (Polarity.NEGATIVE, "NOT")]) en_verb = verb[3:] # remove the leading "to " ja_ta_verb = plain_form(ja_verb, vclass, Tense.NONPAST, polarity) english_prompt = f"People who do {eng_pol} [{en_verb}]" response = f"{ja_ta_verb}人" else: time = pick(nouns.times_past) jtime = japanese(time) en_verb = verb[3:] # remove the leading "to " ja_ta_verb = plain_form(ja_verb, vclass, Tense.PAST, Polarity.POSITIVE) english_prompt = f"A friend who [{en_verb} (PAST)] {time}" response = f"{jtime}{ja_ta_verb}友だち" # elif option == "time": try: user_input = input("translate " + english_prompt + "\n") except UnicodeDecodeError: pass print(f"Sample response is: {response}\n") return # response
from random import choice as pick import db import random dictionary = db.words['easy_difficulty'] secret = pick(dictionary) guesses_taken = [] limit = 10 game_ended = bool(False) def play(): for attempt in range(1,limit): mystery = _doTheThing() print(mystery) if not game_ended: c = input(f"Please take a guess (letter or the word), attempts left: {10-attempt}") guesses_taken.append(c) else: print(f"You won in {limit-attempt} attempts") break def _doTheThing(): global guesses_taken, secret, game_ended text = '' for letter in secret: if letter in guesses_taken:
# import random # print(random.choice(['apple', 'banana', 'cherry', 'ddurian'])) # print(random.randint(1,100)) # random.shuffle(['apple', 'banana', 'cherry', 'ddurian']) from random import choice as pick, randint as magic_number_picker print(pick(['apple', 'banana', 'cherry', 'durian'])) print(magic_number_picker(1, 100)) # random.shuffle(['apple', 'banana', 'cherry', 'ddurian']) #import random # import random as omg_so_random # from random import choice, shuffle, randint # from random import choice as gimme_one, shuffle as mix_up_fruits
from random import choice as pick p_of_goat, p_of_money, rounds = 0, 0, 100000 # large no of rounds for better probability for x in range(rounds): choice = pick(('goat', 'money', 'goat')) # randomly chosing door with either money or goat if choice is 'money': switch = 'goat' # If you chose the door of money the other door has goat p_of_goat += 1 else: switch = 'money' # if you chose the door with goat the other door has money p_of_money += 1 # Calculating probability in percentage m = int((p_of_money/rounds)*100) g = int((p_of_goat/rounds)*100) print('Probability based on event of switching:') # Results print(f'Probability of getting money: {m}%') print(f'Probability of getting goat: {g}%')
print "'You, young one, have been chosen to undertake an epic journey to the depths of Azure'" time.sleep(3) print "'The King has recieved word of your record of monster hunting and has deemed you worthy of this adventure" time.sleep(4) print "'The reward, if you manage to complete the quest, is 5000 Gold'" time.sleep(3) print "'All you have to do is deliver this box to far end of Bleak Falls, someone will be there to collect it'" time.sleep(3) print "'Good Luck'" time.sleep(2) print "You close the scroll and print "Random enemy encounter" time.sleep(2) print "Forest",random.pick(forestMonster) time.sleep(3) dead="1" while dead=="1": print "Your Health",myHealth," Attack",myAttack," Defense ",myDefense time.sleep(1) print "What do you do?" time.sleep(1) answer=raw_input("Attack Defend Item Run ") if answer=="Attack"or answer=="attack": print "You ready your",myWeapon,"and attack the beast" time.sleep(2) if random.choice(chance)==1 or random.choice(chance)==2: print "The beast dies to your mighty",myWeapon,"and you continue on your journey" time.sleep(3)
def random_loot(): generator = pick([WeaponGenerator, ArmorGenerator]) mystery_item = generator() return mystery_item.gen()
def gen(self): generated_item = Item(name=pick(self.nouns), category='armor', strength=randrange(1, 7), required_perception=randrange(1, 10)) return generated_item
def random_word(self): """ find and return random word from file""" return pick(self.words)
from random import choice as pick,randint as magic_num_choser print(pick(["apple","banana","cherry","manish","baba"])) print(magic_num_choser(1,100)) def add(a,b): return a+b
def ask_quit(): if messagebox.askokcancel( "Quit", "Would you like to generate code some other time?"): main_application.destroy() emp_ty = "" min_val = .001 min_val_1 = .01 min_val_2 = .1 min_val_3 = 1 min_val_4 = 10 check_for_two = 2 final_max_val = 100000000000000000 unknown_value_x = float(pick(0, 2)) unknown_value_y = float(pick(0, 2)) unknown_value_z = float(pick(0, 2)) key_var = StringVar() key_var.set("") Enter_key = Entry(canvas, font=("Arial", 10, "italic"), textvariable=key_var) Enterkey = Enter_key.get() Enter_key.place(relwidth=0.3, relheight=0.01885, x=900, y=5) KeyButton = Button(canvas, text="key goes here", font=("Leelawadee UI", 12), bg="black", fg="white",
I'm sorry I'm late but there were | QUANTITY | OBJECT | LOCATION So we have three parts that we can randomise. ''' # The lists quantityList=['loads of', 'like, a million', 'ten thousand', 'a bunch of', 'a shed load of'] objectList=['cats', 'Wombles', 'pink elephants', 'apple turnovers', 'cheese crisps'] locationList=['in my car', 'under my bed', 'on the road', 'in my room', 'down the shops'] # Pick a random element from each list qty=pick(quantityList) obj=pick(objectList) loc=pick(locationList) # Print out the excuse print("I'm sorry I'm late but there were " + qty + " " + obj + " " + loc + ".")
""" Only import what you need!! """ from random import choice as pick, randint as magic_number_chooser # we can rename them print(pick(["apple", "banana", "cherry", "durian"])) print(magic_number_chooser(1, 100)) from random import (choice, randint, shuffle as mix) #Without naming print(choice(["apple", "banana", "cherry", "durian"])) print(randint(1, 100)) x = ["apple", "banana", "cherry", "durian"] mix(x) print(x)
def random_name(): generator = NameGenerator() pool = list(generator.styles.values()) randomly_chosen = pick(pool) return randomly_chosen