Свойство Date
будет возвращать дату в полночь.
Одним из вариантов может быть получение отдельных значений (день / месяц / год) отдельно и сохранение их в нужном вам типе.
var dateAndTime = DateTime.Now;
int year = dateAndTime.Year;
int month = dateAndTime.Month;
int day = dateAndTime.Day;
string.Format("{0}/{1}/{2}", month, day, year);
В модуле operator
есть функции, реализующие стандартные арифметические операторы. При этом вы можете настроить отображение, например:
OperatorFunctions = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.div,
# etc
}
Тогда ваш основной цикл может выглядеть примерно так:
for char in postfix_expression:
if char in OperatorFunctions:
stack.append(OperatorFunctions[char](stack.pop(), stack.pop()))
else:
stack.append(char)
Вам нужно позаботиться о том, чтобы операнды для вычитания и деления были извлечены из стека в правильном заказ.
Просто используйте eval вместе с генерацией строки:
postfix_expression = "34*34*+"
stack = []
for char in postfix_expression:
if char in '+-*/':
expression = '%d%s%d' % (stack.pop(), char, stack.pop())
stack.append(eval(expression))
else:
stack.append(int(char))
print stack.pop()
EDIT : версия стала еще лучше без обработки исключений.
[untested]
from operator import add, sub, mul, div
# read the docs; this is a tiny part of the operator module
despatcher = {
'+': add,
'-': sub,
# etc
}
opfunc = despatcher[op_char]
operand2 = stack.pop()
# your - and / are bassackwards
stack[-1] = opfunc(stack[-1], operand2)