Tôi đang cố gắng viết một mã cho phép tôi tìm thấy một vài bội số đầu tiên của một số. Đây là một trong những nỗ lực của tôi: def printMultiples(n, m):
for m in (n,m):
print(n, end = ' ')
Tôi đã tìm ra rằng, bằng cách đặt def multiples(m, count):
for i in range(count):
print(i*m)
0, nó sẽ chạy qua vòng lặp cho bất kỳ số nào là def multiples(m, count):
for i in range(count):
print(i*m)
1.def printMultiples(n, m):
'takes n and m as integers and finds all first m multiples of n'
for m in (n,m):
if n % 2 == 0:
while n < 0:
print(n)
Sau nhiều tìm kiếm, tôi chỉ có thể tìm thấy một mã mẫu trong Java, vì vậy tôi đã cố gắng dịch nó thành Python, nhưng tôi không nhận được bất kỳ kết quả nào. Tôi có cảm giác tôi nên sử dụng chức năng def multiples(m, count):
for i in range(count):
print(i*m)
2 ở đâu đó trong này, nhưng tôi không biết ở đâu. Ivanleoncz 8.2175 Huy hiệu vàng53 Huy hiệu bạc48 Huy hiệu đồng5 gold badges53 silver badges48 bronze badges Đã hỏi ngày 27 tháng 1 năm 2013 lúc 23:01Jan 27, 2013 at 23:01 2 Nếu bạn đang cố gắng tìm bội số def multiples(m, count):
for i in range(count):
print(i*m)
3 đầu tiên của def multiples(m, count):
for i in range(count):
print(i*m)
1, thì một cái gì đó như thế này sẽ hoạt động:def multiples(m, count):
for i in range(count):
print(i*m)
Ngoài ra, bạn có thể làm điều này với phạm vi: def multiples(m, count):
for i in range(0,count*m,m):
print(i)
Lưu ý rằng cả hai đều bắt đầu bội số tại def multiples(m, count):
for i in range(count):
print(i*m)
5 - nếu bạn muốn thay vào đó bắt đầu vào lúc def multiples(m, count):
for i in range(count):
print(i*m)
1, bạn cần phải bù lại nhiều như vậy:range(m,(count+1)*m,m)
Đã trả lời ngày 27 tháng 1 năm 2013 lúc 23:05Jan 27, 2013 at 23:05
AmberamberAmber 491K81 Huy hiệu vàng618 Huy hiệu bạc546 Huy hiệu đồng81
gold badges618 silver badges546 bronze badges 1 Điều này có làm những gì bạn muốn không? print range(0, (m+1)*n, n)[1:]
Cho m = 5, n = 20 [20, 40, 60, 80, 100]
Hoặc tốt hơn, >>> print range(n, (m+1)*n, n)
[20, 40, 60, 80, 100]
Cho Python3+ >>> print(list(range(n, (m+1)*n, n)))
[20, 40, 60, 80, 100]
Đã trả lời ngày 27 tháng 1 năm 2013 lúc 23:04Jan 27, 2013 at 23:04 Sberrysberrysberry 125K18 Huy hiệu vàng136 Huy hiệu bạc165 Huy hiệu Đồng18 gold badges136 silver badges165 bronze badges 4 Dựa trên các khái niệm toán học, tôi hiểu rằng: - Tất cả các số tự nhiên, chia cho
def multiples(m, count):
for i in range(count):
print(i*m)
7, có def multiples(m, count):
for i in range(count):
print(i*m)
5 là phần còn lại, tất cả đều là bội số của def multiples(m, count):
for i in range(count):
print(i*m)
7
Do đó, tính toán sau đây cũng được áp dụng như một giải pháp (bội số từ 1 đến 100): >>> multiples_5 = [n for n in range(1, 101) if n % 5 == 0]
>>> multiples_5
[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]
Để đọc thêm: - https://www.mathsisfun.com/definitions/natural-number.html
- https://www.mathwizz.com/arithmetic/help/help9.htm
- https://www.calculatorsoup.com/calculators/math/multiples.php
Đã trả lời ngày 23 tháng 1 năm 2019 lúc 16:43Jan 23, 2019 at 16:43 Ivanleonczivanleonczivanleoncz 8.2175 Huy hiệu vàng53 Huy hiệu bạc48 Huy hiệu đồng5 gold badges53 silver badges48 bronze
badges Đã hỏi ngày 27 tháng 1 năm 2013 lúc 23:01 def printMultiples(n, m):
'takes n and m as integers and finds all first m multiples of n'
for m in (n,m):
if n % 2 == 0:
while n < 0:
print(n)
0Nếu bạn đang cố gắng tìm bội số def multiples(m, count):
for i in range(count):
print(i*m)
3 đầu tiên của def multiples(m, count):
for i in range(count):
print(i*m)
1, thì một cái gì đó như thế này sẽ hoạt động:Jan 27, 2013 at 23:18
Ngoài ra, bạn có thể làm điều này với phạm vi:Colonel Panic Lưu ý rằng cả hai đều bắt đầu bội số tại def multiples(m, count):
for i in range(count):
print(i*m)
5 - nếu bạn muốn thay vào đó bắt đầu vào lúc def multiples(m, count):
for i in range(count):
print(i*m)
1, bạn cần phải bù lại nhiều như vậy:84 gold badges389 silver badges457 bronze badges 1 Đã trả lời ngày 27 tháng 1 năm 2013 lúc 23:05 def printMultiples(n, m):
'takes n and m as integers and finds all first m multiples of n'
for m in (n,m):
if n % 2 == 0:
while n < 0:
print(n)
1 double-beep Amberamber13 gold badges32 silver
badges41 bronze badges 491K81 Huy hiệu vàng618 Huy hiệu bạc546 Huy hiệu đồngMay 29, 2019 at 14:13 Điều này có làm những gì bạn muốn không? Cho m = 5, n = 20 def printMultiples(n, m):
'takes n and m as integers and finds all first m multiples of n'
for m in (n,m):
if n % 2 == 0:
while n < 0:
print(n)
2[20, 40, 60, 80, 100]
def printMultiples(n, m):
'takes n and m as integers and finds all first m multiples of n'
for m in (n,m):
if n % 2 == 0:
while n < 0:
print(n)
3Hoặc tốt hơn,Jul 26, 2020 at 8:31
era5toneera5toneera5tone Cho Python3+4 silver badges13 bronze badges Đã trả lời ngày 27 tháng 1 năm 2013 lúc 23:04 Input: def printMultiples(n, m):
'takes n and m as integers and finds all first m multiples of n'
for m in (n,m):
if n % 2 == 0:
while n < 0:
print(n)
4Output: def printMultiples(n, m):
'takes n and m as integers and finds all first m multiples of n'
for m in (n,m):
if n % 2 == 0:
while n < 0:
print(n)
5 Sberrysberry 125K18 Huy hiệu vàng136 Huy hiệu bạc165 Huy hiệu Đồng18
gold badges140 silver badges210 bronze badges Dựa trên các khái niệm toán học, tôi hiểu rằng:Sep 24, 2021 at 5:07 def printMultiples(n, m):
'takes n and m as integers and finds all first m multiples of n'
for m in (n,m):
if n % 2 == 0:
while n < 0:
print(n)
6Tất cả các số tự nhiên, chia cho def multiples(m, count):
for i in range(count):
print(i*m)
7, có def multiples(m, count):
for i in range(count):
print(i*m)
5 là phần còn lại, tất cả đều là bội số của def multiples(m, count):
for i in range(count):
print(i*m)
7Jan 18, 2017 at 15:59 Do đó, tính toán sau đây cũng được áp dụng như một giải pháp (bội số từ 1 đến 100): def printMultiples(n, m):
'takes n and m as integers and finds all first m multiples of n'
for m in (n,m):
if n % 2 == 0:
while n < 0:
print(n)
7Để đọc thêm:Aug 2, 2021 at 23:37 Đã trả lời ngày 23 tháng 1 năm 2019 lúc 16:43 def printMultiples(n, m):
'takes n and m as integers and finds all first m multiples of n'
for m in (n,m):
if n % 2 == 0:
while n < 0:
print(n)
8Tests: def printMultiples(n, m):
'takes n and m as integers and finds all first m multiples of n'
for m in (n,m):
if n % 2 == 0:
while n < 0:
print(n)
9IvanleonczivanleonczMay 15 at 15:28
|