# Enter a code
lengh = 3.14
wide = 1.57
squre = lengh * wide
print(round(wide, 2))
lengh = 3.14
wide = 1.57
squre = lengh * wide
print(round(wide, 2))
2020-11-23
l=['Alice', 'Bob', 'Candy', 'David', 'Ellena']
l[0]='Ellena'
l[1]='Alice'
l[-1]='Bob'
print(l)
l[0]='Ellena'
l[1]='Alice'
l[-1]='Bob'
print(l)
2020-11-23
print(r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.''')
print('\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.')
Whether it's nobler in the mind to suffer.''')
print('\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.')
2020-11-21
# 方法1
list = [i ** 2 for i in range(1, 10)]
print(sum(list))
# 方法2
list2 = [*range(1, 10)]
def square_of_sum(list):
sum = 0
for num in list:
sum += num**2
return sum
sum = square_of_sum(list2)
print(sum)
list = [i ** 2 for i in range(1, 10)]
print(sum(list))
# 方法2
list2 = [*range(1, 10)]
def square_of_sum(list):
sum = 0
for num in list:
sum += num**2
return sum
sum = square_of_sum(list2)
print(sum)
2020-11-21
# 方法1
list = [i**2 for i in range(1,10)]
print(sum(list))
# 方法2
list2 = [*range(1,10)]
def square_of_sum(list):
sum = 0
for num in list:
sum += num
return sum
sum = square_of_sum(list2)
print(sum)
list = [i**2 for i in range(1,10)]
print(sum(list))
# 方法2
list2 = [*range(1,10)]
def square_of_sum(list):
sum = 0
for num in list:
sum += num
return sum
sum = square_of_sum(list2)
print(sum)
2020-11-21
new_names = ['Jenny', 'Ellena', 'Alice', 'Candy', 'David', 'Hally', 'Bob', 'Isen', 'Karl']
# 第一種
names = new_names.copy()
print(names)
'''# 第二種
names = []
name_set = set(names)
name_set.update(new_names)
print(names)
'''
# 第一種
names = new_names.copy()
print(names)
'''# 第二種
names = []
name_set = set(names)
name_set.update(new_names)
print(names)
'''
2020-11-15
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
name_set = set(names)
n='bob'
if n.capitalize()in name_set :#capitalize 首字母大寫
print('True')
else:
print('False')
name_set = set(names)
n='bob'
if n.capitalize()in name_set :#capitalize 首字母大寫
print('True')
else:
print('False')
2020-11-15
冒泡排序完成的,僅供參考。
L = [95.9, 85, 59, 66, 72];
n = len(L)
j = 0
for i in range(n):
for j in range(0, n-j-1):
if L[j] < L[j+1] :
L[j], L[j+1] = L[j+1], L[j]
for count in range(n):
if(count<3):
print(L[count])
else:
break
L = [95.9, 85, 59, 66, 72];
n = len(L)
j = 0
for i in range(n):
for j in range(0, n-j-1):
if L[j] < L[j+1] :
L[j], L[j+1] = L[j+1], L[j]
for count in range(n):
if(count<3):
print(L[count])
else:
break
2020-11-14
先將tuple轉換為list 然后替換list數據 再轉換回tuple就可以了
T = (1, 'CH', [3, 4])
t=list(T)
l=t[2]
L=tuple(l)
t[2]=L
T1=tuple(t)
print(T1)
T = (1, 'CH', [3, 4])
t=list(T)
l=t[2]
L=tuple(l)
t[2]=L
T1=tuple(t)
print(T1)
2020-11-13
L = ['Alice', 66, 'Bob', True, 'False', 100]
i = 0
while i<len(L):
if i % 2 !=0:
print(L[i])
i += 1
i = 0
while i<len(L):
if i % 2 !=0:
print(L[i])
i += 1
2020-11-13