计算机二级:函数基础题

发布于:2025-03-25 ⋅ 阅读:(31) ⋅ 点赞:(0)

函数基础题

第一题

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+=item
    return a
m=0
print(func(m,1,1,2,3,5,7,12,21,33))

输出

85

第十二题


for c in 'Python NCRE':
    if c=="N":
        break
        print(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+=i
    return 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+=1
    elif 'a'<=i<='z':
        b+=1
    else:
        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的整数

网站公告

今日签到

点亮在社区的每一天
去签到