完全な数を完璧にするPythonプログラム
6393 ワード
これは私の12日目の100日目です.今日はFreeCodeCampのCSSプロパティについてもっと勉強しました.いくつかの割り当てを行いました.Pythonプログラムを書くことで、完璧でない数を完璧にしました.以下はその日の私のコードです.
非完全数パーフェクトプログラム
このコードでは、最初のユーザは整数型の数値を与えます.ルートの平方根が与えられたならば、私はルートを定義します.この可能性がないならば、我々はさらに行きます.与えられた後、curr番号の前に初期化します.我々のループがどのくらい続くのか全くわからない.
私は以下のcrootを定義しました.現在の数より少ない数が与えられるならば、我々が取る前に、数は現在の数に等しいです.与えられた数が現在の数より大きいならば、私たちの後の数は現在の数と等しいです.
非完全数パーフェクトプログラム
このコードでは、最初のユーザは整数型の数値を与えます.ルートの平方根が与えられたならば、私はルートを定義します.この可能性がないならば、我々はさらに行きます.与えられた後、curr番号の前に初期化します.我々のループがどのくらい続くのか全くわからない.
私は以下のcrootを定義しました.現在の数より少ない数が与えられるならば、我々が取る前に、数は現在の数に等しいです.与えられた数が現在の数より大きいならば、私たちの後の数は現在の数と等しいです.
n = int(input("enter an integer"))
root = int(n**0.5)
if root**2 == n:
print(f'your number {n} is already perfect.')
else:
# find the perfect numer before and after the number.
before = 0
after = 1
curr_num = 1
while True:
croot = int(curr_num**0.5)
if croot**2 == curr_num:
if curr_num < n:
before = curr_num
else:
after = curr_num
#print(curr_num,before,after)
if after != 1:
if n-before < after-n:
print(f'perfect numbers around {n} are {before} and {after}.')
print(f'your nearest perfect number of {n} is {before}')
print(f'we have to subtract {n-before} to make {n} perfect number.')
break
else:
print(f'perfect numbers around {n} are {before} and {after}.')
print(f'your nearest perfect number of {n} is {after}')
print(f'we have to add {after-n} to make {n} perfect number.')
break
curr_num += 1
12 Day of and python
— Durga Pokharel (@mathdurga)
* More about CSS properties
* Tried to write python program to make non perfect number perfect. , , , pic.twitter.com/9ButCsWhZ7
Reference
この問題について(完全な数を完璧にするPythonプログラム), 我々は、より多くの情報をここで見つけました https://dev.to/iamdurga/day-12-of-100daysofcode-python-program-to-make-non-perfect-number-perfect-2an0テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol