100+ Python challenging programming exercises 8
Question 71
Please write a program which accepts basic mathematic expression from console and print the evaluation result.
请编写一个从控制台接受基本数学表达式的程序,并打印评估结果。
Example: If the following string is given as input to the program:
35+3
Then, the output of the program should be:
38
Hints: Use eval() to evaluate an expression.
Solution:
expression = input()print(eval(expression))
Question 72
Please write a binary search function which searches an item in a sorted list. The function should return the index of element to be searched in the list.
Hints: Use if/elif to deal with conditions.
请编写一个二进制搜索函数,用于搜索排序列表中的项目。函数应