a = 'python'
print 'hello,', a or 'world'
b = ''
print 'hello,', b or 'world'
a為有效字符串,即為true; 則 = true
b為空字符串,即為false; 則 = false
print 'hello,', a or 'world'
b = ''
print 'hello,', b or 'world'
a為有效字符串,即為true; 則 = true
b為空字符串,即為false; 則 = false
2020-10-15
已采納回答 / weixin_慕沐9146932
year = '今年 {} 歲'age = 19if age >= 18:? ? print(year.format(age))
2020-10-15
def greet(c='World'):
print('hello'+','+c)
return
greet()
greet('sb')
print('hello'+','+c)
return
greet()
greet('sb')
2020-10-13
# coding=utf-8
#請分別使用循環和遞歸的形式定義函數,求出1~100的和。
#循環
def sum(n):
i=0
s=0
while i<=n:
s=s+i
i=i+1
print(s)
return
sum(100)
#遞歸
def he(n):
x=0
if n==1:
x=n
else:
x=he(n-1)+n
return x
print(he(100))
#請分別使用循環和遞歸的形式定義函數,求出1~100的和。
#循環
def sum(n):
i=0
s=0
while i<=n:
s=s+i
i=i+1
print(s)
return
sum(100)
#遞歸
def he(n):
x=0
if n==1:
x=n
else:
x=he(n-1)+n
return x
print(he(100))
2020-10-13
# coding=utf-8
def sub_sum(L):
y=0
j=0
i=0
while i<len(L):
if i%2==0:
y=y+L[i]
else:
j=j+L[i]
i=i+1
print(y,j)
return
sub_sum([1,2,3,4])
def sub_sum(L):
y=0
j=0
i=0
while i<len(L):
if i%2==0:
y=y+L[i]
else:
j=j+L[i]
i=i+1
print(y,j)
return
sub_sum([1,2,3,4])
2020-10-13
最新回答 / 慕函數0346336
?# -*- coding: utf-8 -*d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}for key, value in d.items():? ? n=1? ? for score in value:? ? ? ? print('{}的第{}次成績是{}'.format(key, n, score))? ? ? ? n = n+1
Bob的第...
2020-10-13
按題目要求,應該是這么寫吧
L = [95.5, 85, 59, 66, 72]
L2 = sorted(L,reverse=True)
print(L2[0:3])
L = [95.5, 85, 59, 66, 72]
L2 = sorted(L,reverse=True)
print(L2[0:3])
2020-10-10