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.
请编写一个二进制搜索函数,用于搜索排序列表中的项目。函数应
版权声明:本文为博主作者:Hann Yang原创文章,版权归属原作者,如果侵权,请联系我们删除!
原文链接:https://blog.csdn.net/boysoft2002/article/details/135240604