#03超市抹零结账3131
money = eval(input("请输入商品总价:"))
print("抹零后应收{}元".format(int(money)))
#04计算学生成绩的分差和平均分3131
student1_point = eval(input("请输入学生成绩:"))
student2_point = eval(input("请输入学生成绩:"))
print("分差为{},平均分为{}".format(abs(student1_point-student2_point),(student1_point+student2_point)/2))
#05比较运算符比较大小关系3131
num1 = eval(input("请输入数字1:"))
num2 = eval(input("请输入数字2:"))
if num1 > num2:
print("{}和{}中较大的是{}".format(num1, num2, num1))
elif num2==num1:
print("{}和{}一样大".format(num1, num2))
else:
print("{}和{}中较大的是{}".format(num1, num2, num2))
#06手机店打折活动3131
price = eval(input("请输入手机原本价格:"))
discount = eval(input("输入折扣:"))
print("打{}折后,应支付{}元".format(10*discount, price * discount))
#采用蒙特卡罗方法计算圆周率3131
from random import random
from math import sqrt
from time import perf_counter
DARTS = 9999999
hits = 0.0
perf_counter()
for i in range(1, DARTS+1):
x, y = random(), random()
dist = sqrt(x**2 + y**2)
if dist <= 1.0:
hits += 1
pi = 4 * (hits/DARTS)
print("pi的值是{}".format(pi))
print("运行时间是{:.5f}".format(perf_counter()))
标签:num1,num2,format,读书笔记,eval,print,input,第二章 From: https://www.cnblogs.com/lzk-95uu/p/17801566.html