Python学习必备基础知识100问及答案,Python高清PDF电子版下载

摘要:import mathr = float(input("请输入圆的半径:"))defcircleArea:______ math.pi*pow(r, 2)print("圆的面积是:", circleArea)

(图中方式获取Python学习必备基础知识100问及答案PDF电子完整版文件下载链接

1.三元运算

age = 10
ticket = "儿童票"if age < 12 _______ "成人票"
print(ticket)
A. ?
B. else:
C. then
D. else

2.输入函数

trafficLight = ______("请输入信号灯颜色 red, green or yellow:")
if trafficLight == "red":
print("信号灯颜色是:" + trafficLight)
elif trafficLight == "green":
print("信号灯颜色是:" + trafficLight)
else:
print("信号灯颜色是:" + trafficLight)
A. user_input
B. input
C. user_enter
D. enter

3.自定义函数返回值

import math
r = float(input("请输入圆的半径:"))
defcircleArea:
______ math.pi*pow(r, 2)
print("圆的面积是:", circleArea)
A. back
B. send
C. return
D. param

4.成员运算符

color = {0:"red", 1:"yellow", 2:"green", 3:"white"}
v = color.values
for c ______ v:
print(c)
A. in
B. at
C. on
D. by

5.检测字符串是否只由字母组成

name = input("请输入你的英文昵称:")
isLetter = name.______
if isLetter:
print("有效的昵称!")
else:
print("无效的昵称!")
A. isCharacter
B. isChar
C. isLetter
D. isalpha

6.文件操作

f = ______("tryFile. txt", "w")
f.write("I am learning Python programming ! ")
f.close
f = ______("tryFile. txt", "r")
print(f.read)
f.close
A. unwrap
B. unlock
C. untie
D. open

7.导入模块

# program001.py
defred:
print("This flower is red")
defyellow:
print("This flower is yellow")
defgreen:
print("This flower is green")

# program002.py
______ program001# 导入模块
program001.red
program001.yellow
program001.green
A. get
B. import
C. obtain
D. acquire

8.类参数

classFlower:
def__init__( ______, name, color ):
self.name = name
self.color = color
f = Flower("rose", "red")
print("The flower's name is " + f.name)
print("The flower's color is " + f.color)
A. this
B. which
C. self
D. object

来源:思源教育

相关推荐