上面有個(gè)地方缺了一個(gè)縮進(jìn):from decimal import Decimal,ROUND_HALF_UP
def smart_round(x,n):
return str(Decimal(x).quantize(Decimal("0."+"0"*n),rounding=ROUND_HALF_UP))
def smart_round(x,n):
return str(Decimal(x).quantize(Decimal("0."+"0"*n),rounding=ROUND_HALF_UP))
2022-05-29
A = 'Life is {s},you need {p}'
short = 'short'
python = 'Python'
a = A.format(s = short,p = python)
print(a)
B = 'Life {1} short,{2} need {0}'
b = B.format('Python','is','you')
print(b)
short = 'short'
python = 'Python'
a = A.format(s = short,p = python)
print(a)
B = 'Life {1} short,{2} need {0}'
b = B.format('Python','is','you')
print(b)
2022-05-29
實(shí)現(xiàn)任務(wù)最后一步輸出時(shí)可以這樣:print(round(s,2)),但是我第一次做的時(shí)候?qū)懗闪?,發(fā)現(xiàn)結(jié)果和2一樣,省略了末位的0,于是搜索了一下,要實(shí)現(xiàn)保留精確度到指定長(zhǎng)度,自建了一個(gè)函數(shù),但對(duì)我這個(gè)入門級(jí)來說,這個(gè)函數(shù)我看不懂了,就先放著,以后看得懂了再來說說:
from decimal import Decimal,ROUND_HALF_UP
def smart_round(x,n):
return str(Decimal(x).quantize(Decimal("0."+"0"*n),rounding=ROUND_HALF_UP))
輸出時(shí),round改為smart_round
from decimal import Decimal,ROUND_HALF_UP
def smart_round(x,n):
return str(Decimal(x).quantize(Decimal("0."+"0"*n),rounding=ROUND_HALF_UP))
輸出時(shí),round改為smart_round
2022-05-29
def square_of_sum(L):
result=0
for num in L:
result=result+num*num
return result
L=[1,3,5,7,9]
result=square_of_sum(L)
print(result)
result=0
for num in L:
result=result+num*num
return result
L=[1,3,5,7,9]
result=square_of_sum(L)
print(result)
2022-05-25
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
old_score=d['Alice']
print("Alice's old score is {}"
.format(old_score))
d['Alice']=60
print(d)
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
old_score=d['Alice']
print("Alice's old score is {}"
.format(old_score))
d['Alice']=60
print(d)
2022-05-25
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
A=[50, 61, 66]
B=[80, 61, 66]
C=[88, 75, 90]
i=0
while i<3:
d['Alice'].append(A[i])
d['Bob'].append(B[i])
d['Candy'].append(C[i])
i+=1
print(d)
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
A=[50, 61, 66]
B=[80, 61, 66]
C=[88, 75, 90]
i=0
while i<3:
d['Alice'].append(A[i])
d['Bob'].append(B[i])
d['Candy'].append(C[i])
i+=1
print(d)
2022-05-25
最新回答 / qq_慕娘2512265
這段代碼中“for b in S”是錯(cuò)誤的,因?yàn)樵谘h(huán)中修改了集合S的大小,導(dǎo)致了迭代器的大小發(fā)生了變化,從而引發(fā)了錯(cuò)誤。
2022-05-24
# Enter a code
a=1
b=1
while a<=10:
a=a+1
b=b*a
print(b)
a=1
b=1
while a<=10:
a=a+1
b=b*a
print(b)
2022-05-24
# Enter a code
age=20
if age>=18:
print('adult')
elif age>6:
print('teenager')
elif age>3:
print('kid')
else:
print('baby')
age=20
if age>=18:
print('adult')
elif age>6:
print('teenager')
elif age>3:
print('kid')
else:
print('baby')
2022-05-24
# Enter a code
age=20
if age<18:
print('adult)
else:
print('teenager')
age=20
if age<18:
print('adult)
else:
print('teenager')
2022-05-24
最贊回答 / 慕勒9248264
age?=?int(input("請(qǐng)輸入你的年齡:")) if?age?>=?18: ????print("你已經(jīng)成年了") else: ????print("你是未成年人")<...code...>
2022-05-24
最新回答 / 慕設(shè)計(jì)3379244
s=int(input("請(qǐng)輸入年齡"))if 18>s:? ? print("未成年")else:? ? print("已成年"
2022-05-24
print(r'''"To be,or not to be":that is the question.
Whether it's nobler in the mind to suffer.''')
Whether it's nobler in the mind to suffer.''')
2022-05-21
def sums(n):
if n==1:
return 1
return n+sums(n-1)
def sumss(m):
total = 0
for m in range(1,m+1):
total+=m
return total
if n==1:
return 1
return n+sums(n-1)
def sumss(m):
total = 0
for m in range(1,m+1):
total+=m
return total
2022-05-15