Я использую Sublime Text 3 и запускаю код в Ubuntu 16.04 Terminal с интерпретатором Python 3.6.3. Вот часть моего кода, которую я пытаюсь решить:
import sys
print(sys.version_info)
import math
import cmath
import datetime
import random as RAN
from tabulate import tabulate
class Person:
def __init__(self, firstName, lastName, birthdate, email, idx):
self.firstName = firstName
self.lastName = lastName
self.birthdate = birthdate
self.email = email
self.idx = idx
self._age = None
self._age_last_recalc = None
self._recalc_age()
def _recalc_age(self):
today = datetime.date.today()
age = today.year - self.birthdate.year
if today < datetime.date(today.year, self.birthdate.month, self.birthdate.day):
age -= 1
self._age = age
self._age_last_recalc = today
def age(self):
if (datetime.date.today() > self._age_last_recalc):
self._recalc_age()
return self._age
def KeyInPosNumber(n, lower, upper):
while True:
try:
n = int(input('Enter> '))
except ValueError:
print("Invalid input. Please try again.\n")
continue
if not n in range (lower, upper):
print("Value cannot be under {0} or exceed {1}. Please try again.\n".format(lower, upper))
continue
else:
break
def KeyInString(n):
while True:
try:
n = str(input('Enter> '))
except StandardError:
print("Error encountered! Please try again.\n")
continue
else:
break
def main():
girl = Person("Jane", "Doe", datetime.date(1992, 9, 15), "jane.doe@em.com", "53A")
print("")
print("Example student:") #Here's the hard-coded version
print(girl.firstName)
print(girl.lastName)
print(girl.age())
print(girl.email)
print(girl.idx)
print("")
print("")
print("Key in the student's birth year in the format YYYY.")
BYear = 0;
BYear = KeyInPosNumber(BYear, 1900, 2015)
print("\nKey in the student's birth month in the format MM.")
BMonth = 0;
BMonth = KeyInPosNumber(BMonth, 1, 13)
print("\nKey in the student's birth day number in the format DD.")
BDay = 0;
BDay = KeyInPosNumber(BDay, 1, 32)
print("\nKey in the student's first name.")
FName = "";
FName = KeyInString(FName)
print("\nKey in the student's last name.")
LName = "";
LName = KeyInString(LName)
print("\nKey in the student's email address (without '@' and domain.)")
EMail = "";
EMail = KeyInString(EMail)
print("\nKey in the student's registration index.")
RIndex = "";
Rindex = KeyInString(RIndex)
kid = Person(FName, LName, datetime.date(BYear, BMonth, BDay), EMail, RIndex) #Here's the input version
print("")
print(kid.firstName)
print(kid.lastName)
print(kid.age())
print(kid.email)
print(kid.idx)
if __name__ == '__main__':
main()
Я могу распечатать жестко запрограммированную девушку, но не вводную информацию. Потратил много часов, пытаясь решить эту проблему с моим тренером и интернетом.
Ошибка в терминале указывает на линию:
kid = Person(FName, LName, datetime.date(BYear, BMonth, BDay), EMail, RIndex)
Ошибка говорит: TypeError: требуется целое число (получил тип NoneType)
Спасибо за вашу помощь.