挑战Python100题(8)

2023-12-30 16:46:46

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.

请编写一个二进制搜索函数,用于搜索排序列表中的项目。函数应

文章来源:https://blog.csdn.net/boysoft2002/article/details/135240604
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。