Я знаю, что это было задано раньше, но я не могу, чтобы жизнь меня поняла. Я пытаюсь создать простую программу, которая получает две даты, и подсчет показывает, сколько дней осталось между ними.вызов переменной из другой функции в python 3.3?
Это мой текущий код.
month = 0
day = 0
year = 0
def getDate(): #gets the current date
global month
global day
global year
print('What is the current month?')
month = month + int(input())
print('What is the current day?')
day = day + int(input())
print('What is the current year?')
year = year + int(input())
print('The current date is ' + str(month) + '/' + str(day) + '/' + str(year) + '. Is this correct?')
YESNO = input() #confirms date
if YESNO == 'YES' or YESNO == 'yes':
print('Okay.')
else:
getDate()
newMonth = 0
newDay = 0
newYear = 0
def newDate(): #gets the desired countdown date
global newMonth
global newDay
global newYear
print('What is the desired countdown month?')
newMonth = newMonth + int(input())
print('What is the desired countdown day?')
newDay = newDay + int(input())
print('What is the desired countdown year?')
newYear = newYear + int(input())
print('The desired countdown date is ' + str(newMonth) + '/' + str(newDay) + '/' + str(newYear) + '. Is this correct?')
YESNO = input() #confirms date
if YESNO == 'YES' or YESNO == 'yes':
print('Okay.')
else:
newDate()
def COUNTDOWN(): #prints countdown
global newMonth
global newDay
global newYear
global month
global day
global year
if newMonth < Month:
countDownMonth = int(Month) - int(newMonth)
else:
countDownMonth = int(newMonth) - int(Month)
if newDay < Day:
countDownDay = int(Day) - int(newDay)
else:
countDownDay = int(newDay) - int(Day)
if newMonth < Year:
countDownYear = int(Year) - int(newYear)
else:
countDownYear = int(newYear) - int(Year)
print(countDownMonth + '/' + countDownDay + '/' + countDownYear)
getDate()
newDate()
COUNTDOWN()
EDIT Я извиняюсь, я не понял, что это не было отступа. EDIT Мой вопрос: как создать переменную перекрестной функции?
В Python отступы очень важны.Эрго, не могли бы вы правильно отложить свой код? – AVP
Вы не задавали вопрос. Я не знаю, в какой части вашей проблемы вам нужна помощь, чтобы понять. – user2357112
Почему нижние три строки находятся под getDate()? 'global newMonth global newDay global newYear' Также, если вы получаете какую-либо ошибку, отправьте эту информацию о трассировке. – gsmaker