По сути, программа имеет список слов, которые я выучил. Он должен спросить, сколько слов вы хотели бы повторить (назовем это n), а затем выбрать n случайных слов из списка слов. После этого он должен удалить слова, выбранные им из исходного списка, и спросить, хотите ли вы повторить еще, снова попросив вас дать им желаемое количество слов, и это просто промывает и повторяет, пока список окончательно не станет пустым. Вот мой код.
Код: Выделить всё
import random
def word_get(pool, number):
if number > len(pool):
print("Oop, we don't have that many words yet!")
elif len(pool) == 0:
print ("Congrats! You've reviewed all of your learnt words!")
else:
shuffle = random.sample(pool, number)
selected = []
for i in shuffle:
selected.append(i)
for i in pool:
if i in selected:
pool.remove(i)
print (shuffle)
got_kanji = True
return
def next_list():
next = input("would you like another list? (yes or no) ")
return next.lower().startswith("y")
#Program Start
print ("K A N J I S T U D Y")
words = "Book_Store Food Wait Tokyo Kyoto Osaka Read What Temple Before Afternoon Study Know Picture Music Time Bank " \
"Go Weekend Library Sunday Monday Tuesday Wednesday Thursday Friday Saturday Cinema Home_place Between Under " \
"Over Inside Half See Return Teacher English Japanese Korean Chinese Eat Evening University Kanji Ahead " \
"Student Talk Wake_up Me Dad Morning Come Capture Hear Sleep Hospital Town Place Fish Workbook House " \
"Exchange_Student Vegetables Forget Cat Yesterday Meat Bring Year_after_next Counter_for_flat_things Hold " \
"Aniaml Sea Busy Use Years_old Together Terrible Child Last_year Homework Luggage Friend Weather Quiet Later " \
"Mother Father Swim Rest Borrow Teach Hot(Wheather) Cold(wheather) Return_something Classroom Like Tea Really " \
"Name Room Birthday Sit Best Difficult Next To_get_off Death Delete/Turnoff Turn Marriage Hair Play/Hangout " \
"Electricity Road Near Long Window Cease North Wear_from_shoulders_down Cafeteria To_Open Inhale/Smoke/Suck " \
"East Reach Family Park Shoes Company Head South Older_sister Younger_sister to_gain_weight to_stand Joke " \
"West Older_Brother Younger_brother To_take_along Who Traffic_light Move Enter Aid Reside Phone_Call Train " \
"Back/Spine To_Close Bag Side Cheap Power_Outage Car Right Left Store Son To_breakup Corner Sing Flower Laugh " \
"Short Research/Investigation Schdedule Bullet_Train Alcohol Manager Hokkaidou Exercise Popular Kyuushuu " \
"Boat/Ship Cold(thing) Hot(thing) Next/This_Time Singer Resevation Mt.Fuji Kimono Body Husband To_keep(a_pet) " \
"Seasons Autumn Summer Spring Vegetables Warm Chopsticks Older/Senior Short(people) Paper Beauty_Parlor " \
"To_walk Quick Early Baseball Plane World Sleepy Doctor A_long_time Journey Introduce Beginning Famous " \
"Refreshing Stop Sweets/Candy Nagano Climb Hiroshima Question Lake Driving Dream Future Unfortunately/Sadly " \
"To_Work Learn Festival Outside To_get_tired your_wife your/her_husband my_wife my_dear/honey Grandfather " \
"Grandmother Eye Eyebrow Nose Mouth Tooth Ear Hair Head Face Neck Shouler Chest Stomach Arm Hand Leg Finger " \
"Crotch Think Skillful Unskillful Cooking To_Make Cut Start Late/Slow Cheers! Test Cleaning Self/Myself " \
"Shower Walk Vocabulary Interesting/Funny Male Lunch_box Young Composition Winter Hurry To_play(instrument) " \
"To_wash Laundry Remember To_Leave/Throw_away To_end Medicine Village Forest New Dark/Black Red Blue Yellow " \
"White Light_brown Green Deep_Blue Light_Blue Silver Color Grey Purple/Violet Hurts Grades Smile " \
"That_person/Boyfriend Expensive/Tall Girlfriend Rain Rains A_little_bit Obtain To_lose_something Ticket " \
"To_go_out Clothes To_Notice To_run To_be_in_time Nervousness".split()
got_kanji = False
while len(words) > 0:
print ("Number of available words:", len(words))
n = int(input("How many words would you like?: "))
word_get (words, n)
got_kanji = True
if got_kanji:
if next_list():
got_kanji = False
else:
break
Подробнее здесь: https://stackoverflow.com/questions/793 ... ew-program
Мобильная версия