sum1 =0
print('請輸入元素的值:')
a = int(input())
list1 = [a]
print('請輸入數的個數:')
n = int(input())
for i in range
(1, n):
print(sum(list1))
輸出結果:
請輸入元素的值:2
請輸入數的個數:5
24690
img = '★'
list1 = [img]
print('請輸入圖形行數:')
n = int(input())
for i in range
(0, n):
if i ==0:
print(list1[i])
else:
print(list1[i])
輸出結果:5★★★
★★★★★★★
★★★★★
print('請輸入圖形行數:')
n = int(input())
picture = '@'
list1 = [picture]
img = [picture]
for i in range(0, n):
if i == 0:
print(img[i].center(n*2))
else:
print(img[i].center(n*2))
輸出結果:
4@
@@@
@@@@@
@@@@@@@
輸出結果:
4 ★★★★
★★★
★★ ★
- #####輸入兩個正整數m和n,求其最大公約數和最小公倍數。
```python
m = int(input('請輸入第乙個正整數:'))
n = int(input('請輸入第二個正整數:'))
max_1 = 0
min_1 = 0
for i in range(1, m*n+1):
if (m % i == 0) and (n % i == 0):
max_1 = i
# if (i % m == 0) and (i % n == 0):
# min_1 = i
# break
min_1 =int(m * n / max_1)
print('最大公約數為:', max_1, '最小公倍數為:', min_1)
輸出結果:
請輸入第乙個正整數:15
請輸入第二個正整數:18
最大公約數為: 3 最小公倍數為: 90
"se-preview-section-delimiter">
number = [1]
n = 1001
for j in range(1, n):
number2 =
for i in range(1, j):
if j % i == 0:
a = sum(number2)
if a == j:
print(number)
輸出結果:
[1, 6, 28, 496]
class="se-preview-section-delimiter">div>
b =
for i in range(1, 10):
a =
for j in range(1, i+1):
b = a[:]
print(j, '*', i, '=', b[-1], end=" ")
if i == j:
print('\t')
輸出結果:
1 * 1 = 1
1 * 2 = 2 2 * 2 = 4
1 * 3 = 3 2 * 3 = 6 3 * 3 = 9
1 * 4 = 4 2 * 4 = 8 3 * 4 = 12 4 * 4 = 16
1 * 5 = 5 2 * 5 = 10 3 * 5 = 15 4 * 5 = 20 5 * 5 = 25
1 * 6 = 6 2 * 6 = 12 3 * 6 = 18 4 * 6 = 24 5 * 6 = 30 6 * 6 = 36
1 * 7 = 7 2 * 7 = 14 3 * 7 = 21 4 * 7 = 28 5 * 7 = 35 6 * 7 = 42 7 * 7 = 49
1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64
1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81
class="se-preview-section-delimiter">
div>
while true:
n = int(input("請輸入乙個五位數:"))
s = str(n)
if len(s) == 5:
ifs[0] == s[4] and
s[1] == s[3]:
print(n, '是乙個回文數')
else:
print(n, '不是乙個回文數')
else:
print("你的輸入有誤,程式退出")
break
輸出結果:
請輸入乙個五位數:12321
12321 是乙個回文數
請輸入乙個五位數:12345
12345 不是乙個回文數
請輸入乙個五位數:1
你的輸入有誤,程式退出
"se-preview-section-delimiter">
n = int(input('請輸入圖形行數:'))
picture = '@'
list1 = [picture]
img = [picture]
for i in range(0, n):
if i == 0:
print(img[i].center(n*2))
else:
print(img[i].center(n*2))
while i > 0:
print(img[i-1].center(n * 2))
i -= 1
輸出結果:
請輸入圖形行數:4
@
@@@
@@@@@
@@@@
@@@
@@@@@
@@@
@
"se-preview-section-delimiter">
str1 = input("請輸入一串字元:")
a =
char = 0
number = 0
blank = 0
other = 0
for i in range(0, len(str1)):
for j in range(0, len(a)):
ifa[j] == ' ':
blank += 1
elif 'a'
<= a[j] <= 'z'
or'a'
<= a[j] <= 'z':
char += 1
elif "0"
<= a[j] <= '9':
number += 1
else:
other += 1
print('char =', char, 'number =', number, 'blank =', blank, 'other =', other)
輸出結果:
請輸入一串字元:hjsakj2 44hkjbwr3 +fe-w+ +df
char = 17
number = 4 blank = 3 other = 4
python 一些簡單練習(1)
1.輸入乙個數字,求從1到這個數的所有十位數和個位數不相同的數字組合及這樣的數的個數 n 0 x input 請輸入數字 for item in range 1,int x for item2 in range 1,int x if item item2 pass else item3 str it...
web server的一些比較
一,lighttpd簡介 netcraft做的資料調查曾顯示,今年一月份全球使用lighttpd的 為170,000,二月份這個數字達到了7000,000,在短短的乙個月內驚人地增長了400 在這些 中,包括youtube wikipedia和meebo等。而且目前為止,使用lighttpd的 仍在...
一些變數的比較
1 靜態變數 static 什麼是靜態變數 從物件導向的角度觸發,當需要乙個資料物件為整類而非某個物件服務,同時有力求不破壞類的封裝性,既要求此成員隱藏在類的內部,有要求對外不可見的時候,就可以使用static。靜態變數的優點 1 節省記憶體。靜態變數只儲存一處,但供所有物件使用。2 它的值是可以更...