roberthsu2003 / __2024_04_17_mon_wed__

Python與AI人工智慧開發入門
25 stars 4 forks source link

練習:求所有因數 #9

Open roberthsu2003 opened 2 months ago

roberthsu2003 commented 2 months ago

輸入:

請輸入整數,求所有因數:10

輸出:

10的因數是: 1 2 5 10

chesterXalan commented 2 months ago
import pyinputplus as pyip

value = pyip.inputInt('請輸入整數,求所有因數: ', min=1); print(value)
print(f'{value}的因數是:')

for i in range(1, value + 1):
    if value % i == 0:
        print(i, end=' ')

image

MurrayChuang commented 2 months ago
import pyinputplus as pyip
n = pyip.inputInt("請輸入整數,求所有因數:", min=0)
print(n)
print(f"{n}的因數是:")
for i in range(1,n+1):
    if n % i == 0: 
        print(i,end=' ')
image
pear60706 commented 2 months ago
import pyinputplus as pyip

valueInt = pyip.inputInt('請輸入整數,求所有因數:');print(valueInt)
print(f'{valueInt}的因數是:')

for i in range(1,valueInt+1):
    if valueInt % i == 0:
        print(i, end=' ')

lesson7

Tony840705 commented 2 months ago
import pyinputplus as pyip

num = pyip.inputInt("請輸入整數,求所有因數:",min=1)
print(num)
print(f"{num}的因數為:")
for i in range(1,num+1):
    if num % i == 0:
        print(i,end=" ")

作業

chihweihan commented 2 months ago
import pyinputplus as pyip

value = pyip.inputInt("請輸入整數,求所有因數:",min=1)
print(value)
print(f"{value}的因數是:")

for i in range(1,value+1):
    if value % i == 0:
        print(i,end=" ")

image

chiayuben commented 2 months ago
#請輸入整數,輸入[q]離開:
#輸入:
#請輸入整數i,求所有因數:
#輸出:
#i的因數是:
while True:
    value = str.upper(input("請輸入整數,輸入[q]離開:"))
    try:
        if value == 'Q':
            break
        elif eval(value)<1 :
                print(f'輸入數值為{value}數值,需大於零且為整數')
                continue
        try:
            print(f'{value}的因數是:')
            valueInt = int(value)
            num=0
            for i in range(1,valueInt+1):
                if valueInt % i == 0:
                    print(f'{i}',end=' ')
                    num+=1
            print(f',共有{num}個因數')
            print()
        except:    
            print("輸入錯誤,請重新輸入")
            continue
    except:
         print("輸入錯誤,請重新輸入")
print("應用程式結束")

image

Neillo0514 commented 2 months ago

import pyinputplus as pyip

value = pyip.inputInt("請輸入整數,求所有因數:", min=1) print(value) print(f"{value}的因數是:")

for i in range(1,value+1): if value % i == 0: print(i,end=" ") image

YEZZHUANLE commented 2 months ago

import pyinputplus as pyip factors=pyip.inputInt("請輸入整數,求所有因數:");print(factors) print(f"{factors}的因數是")

for i in range(1, factors+1): if factors % i == 0: print(i,end=' ')

螢幕擷取畫面 2024-05-12 221237

JamesHungWJ commented 2 months ago
import pyinputplus as py
num = py.inputInt("請輸入整數,求所有因數:",min=1)
print(num)
print(f"{num}的因數是:")

for i in range(1,num+1):
    if num % i == 0:
        print(i,end=" ")

image

victor1629 commented 1 month ago
import pyinputplus as pypi
value = pypi.inputInt('請輸入整數,求所有因數:')
print(f'{value}')
print(f"{value}的因數是")

for i in range(1,value+1):
     if value % i == 0 :
           print(i,end=' ')  

螢幕擷取畫面 2024-05-13 123704

Tina54321 commented 1 month ago
import pyinputplus as pyip

num = pyip.inputInt("請輸入整數,求所有因數: ", min=1); print(num)
print(f'{num}的因數是:')

for i in range(1, num+1):
    if num % i == 0:
     print(i, end=' ')

image

chchfhah05 commented 1 month ago

`import pyinputplus as pyip

num = pyip.inputInt("請輸入整數,求所有因數:",min=1) print(num) print(f"{num}的因數為:") for i in range(1,num+1): if num % i == 0: print(i,end=" ")`

KIOVER998 commented 1 month ago
import pyinputplus as pyip

num = pyip.inputInt("請輸入整數,求所有因數:",min=1)
print(num)
print(f"{num}的因數為:")
for i in range(1,num+1):
    if num % i == 0:
        print(i,end=" ")

擷取

ccanna commented 1 month ago
while True:
        print("\n請輸入整數,求所有因數(輸入「q」離開):")
        value = input(f'請輸入整數,求所有因數(輸入「q」離開):')

        if value == 'q':
            print('\n結束離開')
            break
        try:  
            value = int(value)
            print(f'您輸入的整數是:{value}')
            print (f'{value}的因數是:')

        except:
            print(f'輸入錯誤{value},請輸入數字')
            continue

        for i in range(1, value+1):
            if value % i == 0:
                print(f'{i}', end=' ')

image

PercJK commented 1 month ago
import pyinputplus as pyip

value = pyip.inputInt("請輸入整數,求所有因數:",min=1)
print(value)
print(f"{value} 的因數是")

for i in range(1,value+1):
    if value % i == 0:
        print(i,end=" ")

lesson7 homework

tary159951123 commented 1 month ago

`importpyinputplus as pyip

value = pyip.inputInt("請輸入整數,求所有因數:",min=1) print(value) print(f"{value} 的因數是")

for i in range(1,value+1): if value % i == 0: print(i,end=" ")`