STR = "Life is {0}, you need {a}"
print(STR.format('short', a ='python'))
print(STR.format('short', a ='python'))
2022-07-11
print(r'''
'\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.'
''')
'\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.'
''')
2022-07-11
def sum_func(num):
total = 0
control = 0
while control <= num:
total += control * control
control += 1
print('count is', total)
sum_func(100)
total = 0
control = 0
while control <= num:
total += control * control
control += 1
print('count is', total)
sum_func(100)
2022-07-08
L = [75, 92, 59, 68, 99]
sum = 0.0
for i in range(len(L)):
sum += L[i]
ave=sum/len(L)
print(ave)
sum = 0.0
for i in range(len(L)):
sum += L[i]
ave=sum/len(L)
print(ave)
2022-07-07
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for item in L:
if item in S:
S.remove(item)
print(S)
S = set([1, 3, 5, 7, 9, 11])
for item in L:
if item in S:
S.remove(item)
print(S)
2022-07-05
最贊回答 / qq_慕斯2338641
//前面是···,表示for循環(huán)語句部分還能沒有結(jié)束,后面的print是包含到for循環(huán)語句中的,然后包含到其中的語句要縮進,沒有縮進就會報錯
2022-07-03
L = [75, 92, 59, 68, 99]
sum = 0.0
for score in L:
sum+=score
print(sum/len(L))
sum = 0.0
for score in L:
sum+=score
print(sum/len(L))
2022-07-02
def deleteScore (name, obj):
if name in obj.keys():
obj.pop(name)
print(obj)
else:
print('不存在!')
print(deleteScore('Alice', d))
if name in obj.keys():
obj.pop(name)
print(obj)
else:
print('不存在!')
print(deleteScore('Alice', d))
2022-07-01
arr = [[50, 61, 66], [80, 61, 66], [88, 75, 90]]
d = {'Alice': [45], 'Bob': [60], 'Candy': [75]}
count = len(arr)
i = 0
while i < count:
for key in d:
for item in arr:
d[key].append(item[i])
i += 1
print(d)
d = {'Alice': [45], 'Bob': [60], 'Candy': [75]}
count = len(arr)
i = 0
while i < count:
for key in d:
for item in arr:
d[key].append(item[i])
i += 1
print(d)
2022-07-01
age = int(input())
if age >= 18:
print("成年人")
elif age >= 6 and age <= 18:
print("青少年")
elif age >= 3 and age <= 6:
print("小孩子")
else:
print("嬰兒")
if age >= 18:
print("成年人")
elif age >= 6 and age <= 18:
print("青少年")
elif age >= 3 and age <= 6:
print("小孩子")
else:
print("嬰兒")
2022-06-29
age = eval(input('請輸入年齡'));
if age >= 18:
print('adult')
else:
print('teenager')
if age >= 18:
print('adult')
else:
print('teenager')
2022-06-28