#the first
template='life is {0}, you need {1}.'
result=template.format('short','Python')
print(result)
#the second
template='you need {p}, life is {s}.'
short='short'
Python='Python'
result=template.format(p=Python, s=short)
print(result)
template='life is {0}, you need {1}.'
result=template.format('short','Python')
print(result)
#the second
template='you need {p}, life is {s}.'
short='short'
Python='Python'
result=template.format(p=Python, s=short)
print(result)
2022-08-19
# Enter a code
L = [[1, 2, 3], [5, 3, 2], [7, 3, 2]]
for x in L:
length = x[0]
width = x[1]
height = x[2]
result = (length*width+length*height+width*height)*2
print(result)
L = [[1, 2, 3], [5, 3, 2], [7, 3, 2]]
for x in L:
length = x[0]
width = x[1]
height = x[2]
result = (length*width+length*height+width*height)*2
print(result)
2022-08-19
# Enter a code
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
L.pop(2)
L.pop(2)
print(L)
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
L.pop(2)
L.pop(2)
print(L)
2022-08-19
# Enter a code
student = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
student.append('Zero')
student.insert(5,'Phoebe')
student.insert(5,'Gen')
print(student)
student = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
student.append('Zero')
student.insert(5,'Phoebe')
student.insert(5,'Gen')
print(student)
2022-08-19
# Enter a code
L = [95.5, 85, 59, 66, 72]
L.sort()
print(L[-1],L[-2],L[-3])
L = [95.5, 85, 59, 66, 72]
L.sort()
print(L[-1],L[-2],L[-3])
2022-08-19
# Enter a code
L = [95.5, 85, 59, 66, 72]
L.sort()
print(L[len(L)-1])
print(L[len(L)-2])
print(L[len(L)-3])
L = [95.5, 85, 59, 66, 72]
L.sort()
print(L[len(L)-1])
print(L[len(L)-2])
print(L[len(L)-3])
2022-08-19
# Enter a code
L = ['Alice', 66, 'Bob', True, 'False', 100]
num = 0
for x in L:
if(num%2==0):
print(x)
num += 1
L = ['Alice', 66, 'Bob', True, 'False', 100]
num = 0
for x in L:
if(num%2==0):
print(x)
num += 1
2022-08-19
# Enter a code
sum = 0
num = 0
while True:
if (num==1000):
break
elif (num%2==0):
sum += num
num += 1
print(sum)
sum = 0
num = 0
while True:
if (num==1000):
break
elif (num%2==0):
sum += num
num += 1
print(sum)
2022-08-18
# Enter a code
num = 1
sum = 1
while num<=10:
sum *= num
num += 1
print(sum)
num = 1
sum = 1
while num<=10:
sum *= num
num += 1
print(sum)
2022-08-18
def func(X):
sum=0
ji=1
if isinstance(X,list):
for n in X:
sum+=n
return sum
if isinstance(X,tuple):
for m in X:
ji*=m
return ji
a=func((1,2,3,4,5))
print(a)
sum=0
ji=1
if isinstance(X,list):
for n in X:
sum+=n
return sum
if isinstance(X,tuple):
for m in X:
ji*=m
return ji
a=func((1,2,3,4,5))
print(a)
2022-08-17
看我看我,思考蠻久了,終于嗑下來了
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
all_source = [[50, 61, 66],[80, 61, 66],[88, 75, 90]]
names = ['Alice','Bob','Candy']
for i in range(len(names)):
n = 0
for j in all_source[n]:
d[names[i]].append(j)
n+=1
print(d)
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
all_source = [[50, 61, 66],[80, 61, 66],[88, 75, 90]]
names = ['Alice','Bob','Candy']
for i in range(len(names)):
n = 0
for j in all_source[n]:
d[names[i]].append(j)
n+=1
print(d)
2022-08-17
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
for i in d:
if i in d:
print(d[i])
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
for i in d:
if i in d:
print(d[i])
2022-08-15
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
k=d['Alice']
k.extend([50,61,66])
c=d['Bob']
c.extend([80,61,66])
p=d['Candy']
p.extend([88,75,90])
print(d)
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
k=d['Alice']
k.extend([50,61,66])
c=d['Bob']
c.extend([80,61,66])
p=d['Candy']
p.extend([88,75,90])
print(d)
2022-08-15
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
scores = [45, 60, 75, 86, 49]
num=0
for x in names:
print(x,':',scores[num])
num+=1
scores = [45, 60, 75, 86, 49]
num=0
for x in names:
print(x,':',scores[num])
num+=1
2022-08-15