欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 培训 > 计算机二级:函数基础题

计算机二级:函数基础题

2025/5/12 11:18:43 来源:https://blog.csdn.net/2301_81197800/article/details/146326920  浏览:    关键词:计算机二级:函数基础题

函数基础题

第一题

r=input("请输入半径:")
c=3.1415926*r*2
print("{:.0f}".format(c))

输出:

Type Error

第二题

a=7
b=2
print(a%2)

输出

1

第三题

ab=4
def my_ab(ab,xy):ab=pow(ab,xy)print(ab,end="\n")
my_ab(ab,2)print(ab)

输出

16
4

第四题

for i in range(0,10,2):print(i,end=",")

输出

0,2,4,6,8,

第五题

L='abcd' 
def f(x,result=["a","b","c","d"]):if x:result.remove(x[-1])f(x[:-1])return result
print(f(L))

输出

[]

第六题

def fun(ss,x=2.0,y=4.0):ss+=x*y
ss=10
print(ss,fun(ss,3))

输出

10 None

第七题

ls=list(range(4))
print(ls)

输出

[0, 1, 2, 3]

第八题

def split(s):return s.split("a")
s="Happy birthday to you!"
print(split(s))

输出

['H', 'ppy birthd', 'y to you!']

第九题

L1=['abc',['123','456']]
L2=['1','2','3']
print(L1>L2)

输出

True

第十题

def func(num):num*=2
x=20
func(x)
print(func(20))

输出

None

第十一题

def func(a,*b):for item in b:a+=itemreturn a
m=0
print(func(m,1,1,2,3,5,7,12,21,33))

输出

85

第十二题


for c in 'Python NCRE':if c=="N":breakprint(c)

输出


第十三题

d=[(-0.71,0.6,1.0),(-1.711,10.16,11.01),(-0.711,0.16,1.01)]
for n in d:print("{}".format(n[0]),end=',')

输出

-0.71,-1.711,-0.711,

第十四题


L1=['1',2,3,1,'5']
print(L1.index("1"))

输出

0

第十五题


ls=['try']
def mtry(lt):lt.append(ls)return lt
print(mtry(mtry(['try'])))

输出

['try', ['try'], ['try']]

第十六题

ls=['try']
def mtry(lt):lt.extend(ls)return lt
print(mtry(mtry(['try'])))

输出

['try', 'try', 'try']

第十七题

k=5
def test(n):global k for i in range(n):k+=ireturn k 
print(k,test(5))

输出

5 15

第十八题

m='I love TaiYUan UNiversity'
a=0
b=0
for i in m:if 'A'<=i<='Z':a+=1elif 'a'<=i<='z':b+=1else:break
print(a,b)

输出

1 0

第十九题

a = '3000'if a < 2000:print("少")
elif a < 4000:print("不多")
else:print("还行")

输出

TypeError: '<' not supported between instances of 'str' and 'int'

第二十题

print(eval('[23,56]'))
print(type(eval('[23,56]')))

输出

[23, 56]
<class 'list'>

第二十一题

a='123'
if a>'python':print("再学python")
else:print("初学python")

输出

初学python

第二十二题

import random
a=random.randint(1,100)
while not a:if a<=50 and a>=40:a=random.random()break
print(a)

输出

随意一个1到100的整数

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词