码迷,mamicode.com
首页 > 其他好文 > 详细

print number

时间:2018-09-08 23:29:29      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:coding   number   must   min   nts   assert   ==   个数   while   

# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name: printsquare
Description :
Author : Administrator
date: 2018/9/8 0008
-------------------------------------------------
"""


def print_square(n):
"""
5(-2,-1,0,1,2)-->range(-2,3)
:param n:
:return:
"""
assert isinstance(n, int), "n must be int"
e = -n // 2
if n == 1:
print("*\t*\n" * 2)
elif n == 2:
print("*\t" * 2, "*")
print("*", "\t" * 2, "*")
print("*\t" * 2, "*")
else:
for i in range(e, n + e + 1):
if i == e or i == n + e:
print("*\t" * (n + 1))
else:
print("*\t" + " \t" * (n - 1) + "*")


# print_square(2)

def print_number(x):
"""
接受一个数字字符串
:rtype: True
"""
w = int("1" + (len(int(x).__str__()) - 1) * "0")
x = int(x)
flag = False
while w:
t = x // w
if flag:
print(t)
else:
if t:
print(t)
flag = True
x %= w
w //= 10
return True


# noinspection PyTypeChecker
print_number("0054321")

print number

标签:coding   number   must   min   nts   assert   ==   个数   while   

原文地址:https://www.cnblogs.com/tnyleyon/p/9610953.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!