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("请输入圆的半径:"))
def circleArea():
______ 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
def red():
print("This flower is red")
def yellow():
print("This flower is yellow")
def green():
print("This flower is green")
# program002.py
______ program001# 导入模块
program001.red()
program001.yellow()
program001.green()
A. get
B. import
C. obtain
D. acquire
8.类参数
class Flower:
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
9.异常处理
try:
int("ten")
______ ValueError as message:
print("Exception occurs ! ", message)
A. except
B. exception
C. catch
D. finally
10.定义类方法
class Dog:
______ cry(self):
print("Dog cries: Wou ! Wou ! ")
class Cat:
______ cry(self):
print("Cat cries: Meo ! Meo ! ")
d = Dog()
d.cry()
c = Cat()
c.cry()
A. function
B. method
C. define
D. def