lecture 1 练习
Assume that two variables, varA and varB, are assigned values, either numbers or strings.
Write a piece of Python code that prints out one of the following messages:
-
"string involved"if eithervarAorvarBare strings -
"bigger"ifvarAis larger thanvarB -
"equal"ifvarAis equal tovarB -
"smaller"ifvarAis smaller thanvarB
For problems such as these, do not include raw_input statements or define the variable varA or varB. Our automating testing will provide values of varA and varB for you - so write your code in the following box assuming varA and varB are already defined.
if isinstance(varA, str) or isinstance(varB, str):
print('string involved')
elif varA > varB:
print('bigger')
elif varA == varB:
print('equal')
else:
print('smaller')