s1 = 'ABC'
s2 = '123'
s3 = 'xyz'
for x in s1:
for y in s2:
for z in s3:
print(x + y + z)
s2 = '123'
s3 = 'xyz'
for x in s1:
for y in s2:
for z in s3:
print(x + y + z)
2024-02-13
num = 0
sum = 0
while True:
if num > 1000:
break
if num%2!=0:
num = num+1
continue
sum = sum+num
num = num+1
print(sum)
sum = 0
while True:
if num > 1000:
break
if num%2!=0:
num = num+1
continue
sum = sum+num
num = num+1
print(sum)
2024-02-13
num = 0
sum = 0
while True:
if num>1000:
break
if num%2==0:
sum = sum+num
num = num+1
print(sum)
sum = 0
while True:
if num>1000:
break
if num%2==0:
sum = sum+num
num = num+1
print(sum)
2024-02-13
num = 1
mul = 1
while num<=10:
mul = mul * num
num = num+1
print(mul)
mul = 1
while num<=10:
mul = mul * num
num = num+1
print(mul)
2024-02-13
L = [75, 92, 59, 68, 99]
sum = 0
for i in L:
sum += i
print(sum)
print(sum/5)
print(sum/len(L))
sum = 0
for i in L:
sum += i
print(sum)
print(sum/5)
print(sum/len(L))
2024-02-13
age = 2
if age>=18:
print('adult')
elif age>=6 and age<18:
print('teenager')
elif age>=3 and age<6:
print('kid')
else:
print('baby')
if age>=18:
print('adult')
elif age>=6 and age<18:
print('teenager')
elif age>=3 and age<6:
print('kid')
else:
print('baby')
2024-02-13
age =30
if age<18:
print('teenager')
else:
print('adult')
if age<18:
print('teenager')
else:
print('adult')
2024-02-13
age = 19
if age>18:
print('adult')
print('dondonqiang age {}'.format(age))
else:
print('minor')
if age>18:
print('adult')
print('dondonqiang age {}'.format(age))
else:
print('minor')
2024-02-13
template = '{l} {i} {s}, {y} {n} {p}'
l = 'Life'
i = 'is'
s = 'short'
y = 'you'
n = 'need'
p = 'Python'
result = template.format(l,i,s,y,n,p)
print(result)
result = template.format(l='Life',i='is',s='short',y='you',n='need',p='Python')
print(result)
l = 'Life'
i = 'is'
s = 'short'
y = 'you'
n = 'need'
p = 'Python'
result = template.format(l,i,s,y,n,p)
print(result)
result = template.format(l='Life',i='is',s='short',y='you',n='need',p='Python')
print(result)
2024-02-08
template = '{}'
con = 'Life is short,you need Python'
result = template.format(con)
print(result)
template = '{0} {1} {2},{3} {4} {5}'
result = template.format('Life','is','short','you','need','Python')
print(result)
con = 'Life is short,you need Python'
result = template.format(con)
print(result)
template = '{0} {1} {2},{3} {4} {5}'
result = template.format('Life','is','short','you','need','Python')
print(result)
2024-02-08
print(r'''
"To be, or not to be": that is the question.Whether it's nobler in the mind to suffer.
''')
"To be, or not to be": that is the question.Whether it's nobler in the mind to suffer.
''')
2024-02-08
print("special string:',\",\,\\\,\\n,\\t")
print("special string:',\",\,\\\\,\\n,\\t")
print("special string:',\",\,\\\\,\\n,\\t")
2024-02-08
>>> a='python'
>>> print('hello,',a or 'world')
hello, python
解釋:短路運算 a or 'world',a為True結果一定為True,直接返回a
>>> b=''
>>> print('hello,',b or 'world')
hello, world
解釋:python講空字符串看作False,b or 'world',b為False,結果取決于'world',直接返回‘world’
>>> print('hello,',a or 'world')
hello, python
解釋:短路運算 a or 'world',a為True結果一定為True,直接返回a
>>> b=''
>>> print('hello,',b or 'world')
hello, world
解釋:python講空字符串看作False,b or 'world',b為False,結果取決于'world',直接返回‘world’
2024-02-07
def func(x):
if isinstance(x, list):
sum = 0
for item in x:
sum += item
return sum
elif isinstance(x, tuple):
sum = 1
for item in x:
sum *= item
return sum
L = [1, 2, 3,4]
t = tuple(L)
print(func(L),func(t))
if isinstance(x, list):
sum = 0
for item in x:
sum += item
return sum
elif isinstance(x, tuple):
sum = 1
for item in x:
sum *= item
return sum
L = [1, 2, 3,4]
t = tuple(L)
print(func(L),func(t))
2024-02-04