挑战Python100题(8)

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.

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

相关推荐

  1. python挑战10秒小程序

    2024-01-06 10:42:01       31 阅读
  2. Python面试-8

    2024-01-06 10:42:01       29 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-06 10:42:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-06 10:42:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-06 10:42:01       82 阅读
  4. Python语言-面向对象

    2024-01-06 10:42:01       91 阅读

热门阅读

  1. vs2019+qt+opencv+open3d

    2024-01-06 10:42:01       54 阅读
  2. TCP和UDP的区别是什么

    2024-01-06 10:42:01       65 阅读
  3. activiti 简介教程

    2024-01-06 10:42:01       59 阅读
  4. SkyWalking部署-K8S

    2024-01-06 10:42:01       59 阅读
  5. 【LeetCode】1193. 每月交易 I

    2024-01-06 10:42:01       55 阅读
  6. LeetCode第102题 - 二叉树的层序遍历

    2024-01-06 10:42:01       56 阅读
  7. 【Android】使用android studio查看内置数据库信息

    2024-01-06 10:42:01       59 阅读
  8. 网络安全协议:保护数据和信息的关键

    2024-01-06 10:42:01       62 阅读
  9. 基于等保合规和滑动标尺模型的云安全建设方法

    2024-01-06 10:42:01       61 阅读
  10. C#的StringBuilder方法

    2024-01-06 10:42:01       54 阅读