学无先后,达者为师

网站首页 Python教程 正文

python如何将一个四位数反向输出_python

作者:JSon liu   更新时间: 2022-07-15 Python教程

将一个四位数反向输出

massage = '''
将一个四位数,反向输出
'''

N = input()
print(N[::-1])
# 输入:	1245
# 输出 :5421

如何计算逆序的四位数

输入一个四位数,得到一个新的四位数。

新数的千位数字、百位数字、十位数字和个位数字分别是原数的个位数、十位数、百位数和千位数。

实现

#!/usr/bin/env python3
#-*- coding:utf-8 -*-
from functools import reduce
#---------------------
def returnReverseNumberString(ls):
    ls.reverse()
    return reduce(lambda x,y:x+y,ls)
    
def returnNumberCharList(x):
    resultList=[]
    for temp in x:
        resultList.append(temp)
    return resultList

def main():
    try:
        number=input()
        print(f"{eval(returnReverseNumberString(returnNumberCharList(number)))}")
    except Exception as e:
        print("The data's type of inputing is bad!")
        print("Error:",e)
    finally:
        pass
#---------------------
main()

输出

1234
4321

原文链接:https://blog.csdn.net/weixin_45912307/article/details/108620063

相关推荐

栏目分类
最近更新