print('hey, u')
print('hey', ' u')
x,y,z = 1,2,3
print(x, y, z)
print('x = %d, y = %d, z = %d' %(x,y,z)) 
print('x = {}, y = {}, z = {}'.format(x,y,z)) 
print(f'x = {x}, y = {y}, z = {z}') 
print(x) 
print(y)
print(z)
print(x, end=' ') 
print(y, end=' ')
print(z)
x1, y1 = 1.2, 3.57
x2, y2 = 2.26, 8.7
print('{:-^40}'.format('输出1'))
print('x1 = {}, y1 = {}'.format(x1, y1))
print('x2 = {}, y2 = {}'.format(x2, y2))
print('{:-^40}'.format('输出2')) 
print('x1 = {:.1f}, y1 = {:.1f}'.format(x1, y1))
print('x2 = {:.1f}, y2 = {:.1f}'.format(x2, y2))
print('{:-^40}'.format('输出3')) 
print('x1 = {:<15.1f}, y1 = {:<15.1f}'.format(x1, y1))
print('x2 = {:<15.1f}, y2 = {:<15.1f}'.format(x2, y2))
print('{:-^40}'.format('输出3')) 
print('x1 = {:>15.1f}, y1 = {:>15.1f}'.format(x1, y1))
print('x2 = {:>15.1f}, y2 = {:>15.1f}'.format(x2, y2))

name1, age1 = 'Bill', 19
name2, age2 = 'Hellen', 18
title = 'Personnel Information'
print(f'{title:=^40}') 
print(f'name: {name1:10}, age: {age1:3}')
print(f'name: {name2:10}, age: {age2:3}')
print(40*'=')

:print()有三种常用用法:1、使用%格式化输出。2、使用format()格式化输出。3、使用f字符串格式化输出

r1 = eval('1 + 2') 
print(type(r1), r1)
r2 = eval('[1, 6, 7.5]')
print(type(r2), r2)
r3 = eval('"python"')
print(type(r3), r3)
r4 = eval('7, 42') 
print(type(r4), r4)

x, y = eval(input('Enter two oprands: ')) 
ans = x + y
print(f'{x} + {y} = {ans}')
print(f'{type(x)} + {type(y)} = {type(ans)}')

eval()的用法:可以把输入的数据类型转变为我们想要的数据类型。

ans1 = 0.1 + 0.2
print(f'0.1 + 0.2 = {ans1}')
from decimal import Decimal
ans2 = Decimal('0.1') + Decimal('0.2')
print(f'0.1 + 0.2 = {ans2}')

0.1,0.2在二进制浮点中没有精确的表达

Decimal()是将数字舍到十进制下的位数然后再进行运算

print(chr(0x1f600), end = " ")
print(chr(0x1f601), end = " ")
print(chr(0x1f602), end = " ")
print(chr(0x1f603), end = " ")
print(chr(0x1f604))
print(chr(10000), end=" ")
print(chr(0x025b), end=" ")
print(chr(0x2708), end=" ")
print(chr(0x00A5), end=" ")
print(chr(0x266b))
# ord()返回字符的unicode编码
print(ord('a'), end = " ")
print(ord('b'), end = " ")
print(ord('c'))
print(ord('A'), end = " ")
print(ord('B'), end = " ")
print(ord('C'))
print(ord('0'), end = " ")
print(ord('1'), end = " ")
print(ord('2'))

chr()的用法:在圆括号内打入Unicode编码可以得到对应的字符(编码的尽职要求是十进制,若遇到二进制等,就在前面加0b等);

ord()的用法:在圆括号内打入字符可以得到对应的编码

from math import sqrt
n = float(input('输入一个数:'))
ans1 = sqrt(n)
ans2 = n**0.5
print('%.2f的平方根是: %.2f' %(n, ans1)) 
print('{:.2f}的平方根是: {:.2f}'.format(n, ans2)) 
print(f'{n:.2f}的平方根是: {ans2:.2f}')  

for i in range(3):
    x=eval(input())
    y=x**365
    print(f'{x}的365次方是{y}')

import math
from math import pi
M=[47,67]
for i in range(2):
  p=1.038
  c=3.7
  K=5.4*10**(-3)
  T=eval(input())
  tw=100
  ty=70
  t=(pow(M[i],2/3)*c*pow(p,1/3))/(K*pow(pi,2)*pow((4*pi)/3,2/3))*math.log(0.76*(T-tw)/(ty-tw))
  min=t//60
  second=round(t-min*60,2)

  print(f'T={T}℃,t={min}分{second}秒')

本次实验回顾了math库中函数的调用。比如math.pi,math.log(x)。;Decimal库中Decimal()的调用。除此以外,对输出内容的宽度以及精度也进行了熟悉。

很多内容由于不用导致忘了,但经过复习后又进一步掌握了。

我比较喜欢那个大饼实验,里面使用了math库中的pi,多行字符串,第一次发现python可以这样有趣的方式输出。

 

 

 

 

posted on 2022-03-25 22:50  JskyR  阅读(83)  评论(4)    收藏  举报