标签:div lse 回文数 用户 -name ntb int else 输出
class MyYear(object):
def init(self):
self.year = int(input("请输入年份:"))
def show_season(self):
for i in range(1, 13):
if i in (12, 1, 2):
print(i, "冬季")
elif i in (3, 4, 5):
print(i, "春季")
elif i in (6, 7, 8):
print(i, "夏季")
else:
print(i, "秋季")
def isleap(self):
if self.year % 4 == 0 and self.year % 100 != 0 or self.year % 400 == 0:
print(self.year, "是闰年")
else:
print(self.year, ‘不是闰年‘)
def year_sum(self):
a = 1
sum = 0
while a <= self.year:
sum += a
a += 1
print(sum)
def check_num(self):
if self.year == self.year[::-1]:
print(self.year,‘是回文数,回文数是‘,self.year[::-1])
else:
print(self.year,"不是回文数")
def show_leap_year(self):
for i in range(1,self.year+1):
if i % 4 == 0 and i % 100 != 0 or i % 400 == 0:
print(i, "是闰年")
else:
pass
def show_num_div(self):
for i in range(1,self.year+1):
if i % 9 == 0 or ‘9‘ in str(i) :
print(i)
else:
pass
# b =MyYear()
# b.year_sum()
# b.show_leap_year()
# b.show_num_div()
class MyNum(object):
def init(self):
self.num = int(input("请输入一个整数数字:"))
def show_num(self):
for i in range(1,self.num+1):
print(i)
def calc_sum(self):
a = 1
sum = 0
while a<= self.num:
sum += a
a +=1
print(sum)
def calc_odd_sum(self):
a = 1
sum = 0
while a <= self.num:
if a%2==1:
sum += a
a +=2
else:
pass
print(sum)
def calc_even_sum(self):
sum = 0
for i in range(1,self.num+1):
if i%2==0:
sum += i
i += 1
print(sum)
def show_num_div(self):
for i in range(1,self.num+1):
if i%7==0:
print(i)
def check_num(self):
if self.num == self.num[::-1]:
print(self.num,‘是回文数,回文数是‘,self.num[::-1])
else:
print(self.num,"不是回文数")
if name == ‘main‘:
c=MyNum()
# c.calc_sum()
# c.calc_odd_sum()
# c.calc_even_sum()
# c.show_num_div()
c.check_num()
标签:div lse 回文数 用户 -name ntb int else 输出
原文地址:https://www.cnblogs.com/Stubbornlyn/p/13172131.html