华南理工大学 Python第5章课后小测-2(South China University of technology Python Chapter 5 after class quiz-2)-python

华南理工大学 Python第5章课后小测-2(South China University of technology Python Chapter 5 after class quiz-2)

``````ls = []
def func(a, b):
ls.append(b)
return a*b
s = func("hi", 2)
print(s, ls)``````
``````def count (N):
if (N <= 0):
return "请输入一个正整数"
if (N > 9):
return "计数结束"
else:
return count(N+1)
print(count(6))``````
``````def my_function(s,*ks):
print(ks[0])
my_function("a", "b", "c")``````
``````def test():
return 'abc', 100, [0, 1, 2]
a, b, c = test()
print(a)``````
``````def f(s):
return s+s``````
``````def reverse (s):
return  reverse  (s[1:])+s[0]``````
``````def reverse (s):
if s=="":
return s
else:
return  reverse  (s[1:])+s[0]``````
``````cnum= 1
acc= 0
def rsum():
global cnum
global acc
if cnum== 6:
return acc
else:
acc = acc + cnum
cnum = cnum + 1
return rsum()``````
``````def f(s):
return s+s``````
``````c=1
c=100
return c+1 ``````
``````n = 0
def func(a,b):
n = b
return a+n
s = func(1, 2)
print(s, n)``````
``````x = 54321
y = 0
fac = 10000
while x:
y += fac*(x%10)
x = x//10
print(y)
print(x+y)``````
``````a,b,c=-2,4,6
s,w,t=1,3,5
if c>0:
s=a+b
if a<=0:
if c<=0:
w=a-b
else:
if c>0:
w=a-b
else:
t=c
c=a+b
print("a={},b={},c={}".format(a,b,c))
print("s={},w={},t={}".format(s,w,t))``````
``````sum = 0
for i in range(__(1)__):
sum = __(2)__
print(sum)``````
``````sum = 0
i = 100
while i>0:
if __(1)__:
sum =  sum + 1
__(2)__
print(sum)``````
``````len = eval(input("输入要打印的行数:"))
for i in __(1)__(len):
for j in range(0, len - i):
print(end=" ")
for t in range(2 * i + 1):
print("*", end="")
__(2)__``````
``````m=eval(input("请输入一个整数:"))
t=0
for i in range(2,__(1)__):
if m%i==0:
t=1
__(2)__               #退出循环
if t==__(3)__:
print(m,"是素数")
else:
print(m,"不是素数")``````
``````n=eval(input("请输入一个正整数:"))

s=str(n)+"=1"    #保存结果，最后再输出

a=2
while n>=a:
if  __(1)__:
s=s+"*"+ __(2)__
n=n//a
else:
__(3)__
print(s)``````
``````import random
__(1)__.seed(100)
m=eval(input())
s=0
for j in range(m):
f=random.uniform(__(2)__)
s+=f
print(f)
print('平均值是：',__(3)__)``````
``````def __(1)__:
sum = 0
for i in range(n):
sum = sum + __(2)__
return sum
n = int(input("请输入数字:"))
r = f(n)
print("1～{}的平方和是{}".format(n, r))``````
``````def fib(n):
if __(1)__:
return 1
else:
return __(2)__ + __(3)__
n = eval(input(“输入正整数N”))
print(fib(n))``````
``````def reverse(s):
if __(1)__:
return s
else:
return __(2)__+ s[0]
str = input("请输入一个字符串: ")
print(reverse(str))``````
``````def myMax(a,b):
if __(1)__:
return a
else:
__(2)__

a = eval(input())
b = eval(input())

print(myMax(a,b))``````
``````def mul(n):
if n==1:
__(1)__
else:
__(2)__

n = int(input())
print(mul(n))``````
————————
``````ls = []
def func(a, b):
ls.append(b)
return a*b
s = func("hi", 2)
print(s, ls)``````
``````def count (N):
if (N <= 0):
return "请输入一个正整数"
if (N > 9):
return "计数结束"
else:
return count(N+1)
print(count(6))``````
``````def my_function(s,*ks):
print(ks[0])
my_function("a", "b", "c")``````
``````def test():
return 'abc', 100, [0, 1, 2]
a, b, c = test()
print(a)``````
``````def f(s):
return s+s``````
``````def reverse (s):
return  reverse  (s[1:])+s[0]``````
``````def reverse (s):
if s=="":
return s
else:
return  reverse  (s[1:])+s[0]``````
``````cnum= 1
acc= 0
def rsum():
global cnum
global acc
if cnum== 6:
return acc
else:
acc = acc + cnum
cnum = cnum + 1
return rsum()``````
``````def f(s):
return s+s``````
``````c=1
c=100
return c+1 ``````
``````n = 0
def func(a,b):
n = b
return a+n
s = func(1, 2)
print(s, n)``````
``````x = 54321
y = 0
fac = 10000
while x:
y += fac*(x%10)
x = x//10
print(y)
print(x+y)``````
``````a,b,c=-2,4,6
s,w,t=1,3,5
if c>0:
s=a+b
if a<=0:
if c<=0:
w=a-b
else:
if c>0:
w=a-b
else:
t=c
c=a+b
print("a={},b={},c={}".format(a,b,c))
print("s={},w={},t={}".format(s,w,t))``````
``````sum = 0
for i in range(__(1)__):
sum = __(2)__
print(sum)``````
``````sum = 0
i = 100
while i>0:
if __(1)__:
sum =  sum + 1
__(2)__
print(sum)``````
``````len = eval(input("输入要打印的行数:"))
for i in __(1)__(len):
for j in range(0, len - i):
print(end=" ")
for t in range(2 * i + 1):
print("*", end="")
__(2)__``````
``````m=eval(input("请输入一个整数:"))
t=0
for i in range(2,__(1)__):
if m%i==0:
t=1
__(2)__               #退出循环
if t==__(3)__:
print(m,"是素数")
else:
print(m,"不是素数")``````
``````n=eval(input("请输入一个正整数:"))

s=str(n)+"=1"    #保存结果，最后再输出

a=2
while n>=a:
if  __(1)__:
s=s+"*"+ __(2)__
n=n//a
else:
__(3)__
print(s)``````
``````import random
__(1)__.seed(100)
m=eval(input())
s=0
for j in range(m):
f=random.uniform(__(2)__)
s+=f
print(f)
print('平均值是：',__(3)__)``````
``````def __(1)__:
sum = 0
for i in range(n):
sum = sum + __(2)__
return sum
n = int(input("请输入数字:"))
r = f(n)
print("1～{}的平方和是{}".format(n, r))``````
``````def fib(n):
if __(1)__:
return 1
else:
return __(2)__ + __(3)__
n = eval(input(“输入正整数N”))
print(fib(n))``````
``````def reverse(s):
if __(1)__:
return s
else:
return __(2)__+ s[0]
str = input("请输入一个字符串: ")
print(reverse(str))``````
``````def myMax(a,b):
if __(1)__:
return a
else:
__(2)__

a = eval(input())
b = eval(input())

print(myMax(a,b))``````
``````def mul(n):
if n==1:
__(1)__
else:
__(2)__

n = int(input())
print(mul(n))``````