日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 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

欄目分類
最近更新