Итак, я создаю генератор даты для своей подруги, и я не могу показаться, что программа удаляет дату из пула образцов после ее выбора. dateChoice()
делает фактический выбор даты, которая работает, находит, но dateRemover()
, похоже, не работает. Я прочитал множество текстовых писем и чтений, и я не могу заставить это работать. Спасибо!
import random
#Imports date list
dateList = open("file", 'r+')
dates = dateList.readlines()
line = "-----------------------------------------"
choice = ""
date = ""
#Selects a Date
def dateChoice():
date = random.choice(dates)
print("Your date is: {}".format(date)
#Removes date from list
def dateRemover():
choice = input("Would you like to remove the date from the list?")
if str.upper(choice) in ["Y", "YES"]:
print(line)
dateList.seek(0)
for i in dates:
if i != date:
dateList.write(i)
dateList.truncate()
print("All is done")
elif str.upper(choice) in ["N", "NO"]:
print(line)
print("Okay. your date is still in the system!")
else:
print(line)
print("Please answer with either Yes or No")
dateRemover()
#Start of program
def start():
dateChoice()
dateRemover()
#Runs programs
start()