python練習:ユーザーに整数を入力し、2つの整数rootとpwrを出力して0を満たすプログラムを作成します.

4694 ワード

python練習:ユーザーに整数を入力し、2つの整数rootとpwrを出力して0を満たすプログラムを作成します.
難点:input()関数の戻り値は文字列タイプで、整数に変換する必要があります.whileサイクル判定条件ans**3
 1 print("————————————————————————————")
 2 #         
 3 x=int(input(''))
 4 ans=0
 5 while ans**3<abs(x):
 6     ans=ans+1
 7 if ans**3!=abs(x):
 8     print(x,'      ')
 9 else:
10     if x<0:
11         ans=-ans
12     print('   ',x,'     ',ans)
13 print("————————————————————————————")
14 y=int(input(''))
15 root=0
16 for pwr in range(1,6):#  for       
17     while root**pwr#         
18         root=root+1
19     if root**pwr!=abs(y):
20         print(y,'  ',pwr,'    ')
21     else:
22         if y<0:
23             root=-root
24         print('   ',y,' ',pwr,'    ',root)
25     root=0#   for        root=0

 
転載先:https://www.cnblogs.com/ming-4/p/10246581.html