I developed this code for Python 3 in order to ask the user if they wish to continue:
def dnv():
b = input('Would you like to try again? Type 1 for "yes" and 0 for "no": ')
if b == '1':
return run()
if b == '0':
return print('See you later!')
run() is any program's main function. But now I'm taking a course on Python 2 and I've tried to adapt it on an algorithm I took from there, with no success. The objetive was to determine how many days are between two dates. I believe the relevant part is:
def inputs():
year1 = input('Type the first year: ')
month1 = input('Type the first month: ')
day1 = input('Type the first day: ')
year2 = input('Type the second year: ')
month2 = input('Type the second month: ')
day2 = input('Type the second day: ')
print daysBetweenDates(year1, month1, day1, year2, month2, day2)
def dnv():
answer = input('Would you like to try again? Type "y" for yes and "n" for no: ')
if answer == 'y':
return inputs()
else:
print('See you later!')
I get a NameError: name 'y' is not defined (analogue to 'n') though everytime I type y or n. I've also tried to modify if answer == 'y' to:
if answer.lower().startswith('y'):
return inputs()
Again with no success. What am I missing? Thank you!
input()works differently from python3input(). Tryraw_input()instead.