"""补充练习:标识符、关键字、变量、基本类型、输入输出及常用运算。 输入:标识符候选字符串;一行两个整数 a、b;一行两个实数 x、y。 学习说明: - keyword 模块可以识别 Python 保留关键字,例如 if、for;关键字不能作为变量名。 - isidentifier() 检查字符串是否符合标识符书写规则。 - input() 读到字符串;int()、float() 将输入转换成相应数值类型。 - +、-、*、** 是算术运算;/、//、% 分别表示除法、整除、取余。 - ==、!=、<、<=、>、>= 是关系运算;and、or、not 是逻辑运算,结果为布尔值。 - 除法和取余前必须确认除数不为 0。 """ import keyword candidate = input().strip() # 一行两个整数、再一行两个实数;拆分后分别转换数据类型。 a, b = map(int, input().split()) x, y = map(float, input().split()) is_valid_identifier = candidate.isidentifier() and not keyword.iskeyword(candidate) # type(x).__name__ 只用于把变量的类型名称显示出来。 print("identifier valid:", is_valid_identifier) print("is keyword:", keyword.iskeyword(candidate)) print("types:", type(candidate).__name__, type(a).__name__, type(x).__name__) print("boolean type:", type(is_valid_identifier).__name__) print("integer arithmetic:", a + b, a - b, a * b, a ** 2) if b != 0: print("integer division:", a / b, a // b, a % b) else: print("integer division: undefined when b is 0") print("real arithmetic:", x + y, x - y, x * y) if y != 0: print("real division:", x / y) else: print("real division: undefined when y is 0") print("relations:", a == b, a != b, a < b, a <= b, a > b, a >= b) print("logical:", a > 0 and b > 0, a > 0 or b > 0, not (a == b))