'''
@Author: your name
@Date: 2020-07-23 23:13:36
@LastEditTime: 2020-07-23 23:35:12
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: \vscode_py\day17.py
'''
# Question 65
# Please write assert statements to verify that every number in the list [2,4,6,8] is even.
def Q65():
l=[2,4,6,8]
for i in l:
assert i%2==0,"{} is not even".format(i)
print("end")
# Question 66
# Please write a program which accepts basic mathematic expression from console and print the evaluation result.
def Q66():
expression=input("expression: ")
ans=eval(expression)
print(ans)
# Question 67
# 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.
def Q67(li,element):
import math
low=0
high=len(li)-1
# print(high)
while low<=high:
mid=round((high+low)/2)
# print(mid)
if element>li[mid]:
low=mid+1
elif element<li[mid]:
high=mid-1
else:
return mid
return None
# 使用random.uniform(a,b)生成指定范围(a,b)的随机数
# Question 68
# Please generate a random float where the value is between 10 and 100 using Python module.
def Q68():
import random
print("random:{}".format(random.uniform(10,100)))
# Question 69
# Please generate a random float where the value is between 5 and 95 using Python module.
def Q69():
import random
# ans=random.random()*100-5
ans=random.uniform(5,95)
print("ans:{}".format(ans))
if __name__ == "__main__":
# Q65()
# Q66()
# li=[2,4,6,8]
# print(Q67(li,5))
# Q68()
Q69()