Python For Loop家庭作業(yè)

因此,這個問題并不難,只是用了一種令人困惑的方式。我嘗試了3種解決方案,但沒有一種是正確的。我已經(jīng)付出了我真正的努力,所以我希望其他人能在這里幫助我。問題是:

使用for循環(huán),編寫以下程序:所有two-digit數(shù)字(等于構(gòu)成給定數(shù)字的數(shù)字乘積的兩倍)顯示在column.中

以下是我迄今為止嘗試過的3種解決方案:

1.

num = int(input("Enter a two-digit number: "))
digitArr = []

for i in str(num):
    digitArr.append(i)

result = 1

for j in digitArr:
    result = result * int(j)
result = result ** 2 #here

for i in range(10, 100):
    tempDigitArr = []
    for j in str(i):
        tempDigitArr.append(j)
    tempResult = 1
    for k in tempDigitArr:
        tempResult = tempResult * int(k)
    tempResult = tempResult ** 2 #here
    if tempResult == result:
        print(i)
        tempResult = 1
        continue
    else:
        tempResult = 1
        continue
num = int(input("Enter a two-digit number: "))
digitArr = []

for i in str(num):
    digitArr.append(i)

result = 1

for j in digitArr:
    result = result * int(j)
result = result ** 2 #here

for i in range(10, 100):
    tempDigitArr = []
    for j in str(i):
        tempDigitArr.append(j)
    tempResult = 1
    for k in tempDigitArr:
        tempResult = tempResult * int(k)
    tempResult = tempResult ** 2 #here
    if tempResult == result:
        print(i)
        tempResult = 1
        continue
    else:
        tempResult = 1
        continue
num = int(input("Enter a two-digit number: "))
digitArr = []

for i in str(num):
    digitArr.append(i)

result = 1

for j in digitArr:
    result = result * int(j)

for i in range(10, 100):
    tempDigitArr = []
    for j in str(i):
        tempDigitArr.append(j)
    tempResult = 1
    for k in tempDigitArr:
        tempResult = tempResult * int(k)
    if tempResult == result:
        print(i)
        tempResult = 1
        continue
    else:
        tempResult = 1
        continue

是的,如果有人想知道;我的課程使用auto-check系統(tǒng);-;

? 最佳回答:

方法非常簡單

test = range(10,99+1)

for num in test:

    prod = 1
    for digit in str(num): prod = prod * int(digit)

    if num == 2*prod:
        print(num)

有趣的事實:只有36個符合這個要求

主站蜘蛛池模板: 一区二区三区免费精品视频| 久久国产一区二区三区| 中文字幕一区二区三区精彩视频| 日韩一区二区a片免费观看| 一区二区三区人妻无码| 亚洲av无码天堂一区二区三区| 无码丰满熟妇一区二区| 中文字幕视频一区| 日本亚洲国产一区二区三区| 国产一区二区三区电影| 中文字幕精品一区二区| 久久精品一区二区免费看| 亚洲爽爽一区二区三区| 国产韩国精品一区二区三区| 国产一区二区三区在线免费观看 | 久久久久人妻一区精品果冻| 亚洲日韩AV一区二区三区中文| 末成年女A∨片一区二区| 国产在线精品一区二区三区直播| 日韩精品无码Av一区二区| 日本一区二区三区在线看| 在线观看一区二区精品视频| 亚洲AV无码一区二区三区网址 | 夜色阁亚洲一区二区三区| 国产精品一区二区资源| 国产丝袜一区二区三区在线观看| 国产精品久久久久一区二区| 精品一区二区三区无码视频| 精品视频一区在线观看| 一区二区三区福利| 国产在线一区视频| www一区二区www免费| 国产内射999视频一区| 亚洲视频一区调教| 亚洲欧美日韩国产精品一区| 日本高清天码一区在线播放| 无码精品前田一区二区| 国偷自产一区二区免费视频| 亚洲图片一区二区| 激情无码亚洲一区二区三区| 美女AV一区二区三区|