实验1-7
2022/3/27 6:24:20
本文主要是介绍实验1-7,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
task1_1
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)
task1_2
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('输出4')) print('x1 = {:>15.1f},y1 = {:>15.1f}'.format(x1,y1)) print('x2 = {:>15.1f},y2 = {:>15.1f}'.format(x2,y2))
task1_3
name1, age1 = 'Bill',19 name2, age2 = 'Hellen',18 title = 'personal 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.print(x, y, z)
2.print('x = {}, y = {}, z = {}'.format(x,y,z))
3.print(f'name: {name1:10}, age: {age1:3}')
task2_1
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)
task2_2
x,y = eval(input('Enter two oprands:')) ans = x + y print(f'{x}+{y}={ans}') print(f'{type(x)}+{type(y)}={type(ans)}')
总结:eval()
1.r1 = eval('1 + 2')
2.x, y = eval(input('Enter two oprands: '))
task3
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}')
task4
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)) 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()和ord()是编码与相对符号之间转换的转换符
task5_1
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}')
task5_2
from math import pi text = ''' 好奇心是人的天性。 理想情况下,学习新东西是让人愉快的事。 但学校里的学习似乎有点像苦役。 有时候,需要画一个大饼,每次尝试学一些新鲜的,才会每天变得更好一点点。 ''' print(text) r = float(input('给学习画一个大饼,大饼要做的很大,半径要这么大: ')) circle = 2*pi*r print(f'绕起来,大饼的圆周有这么长, {circle}, 够不够激发你探索未知的动力...')
task6
x = eval(input('请输入数字:')) y = x**365 print(x,'的365次方是:',y)
task7
from math import* p = 1.038 c = 3.7 k = 5.4*10**-3 M = 67 Tw = 100 Ty = 70 T0 = int(input('输入一个温度T0:')) x = (0.76*((T0-Tw)/(Ty-Tw))) n = log(x,e) t = ((M**2/3)*c*(p**1/3))/(k*(pi**2)*((4*pi/3)**2/3))*n print('T0=',T0 , 't=',t)
实验总结:
通过本次实验我能够熟练的使用print()的各种表达形式与用法并能够在众多选择种择优使用,因而我的输入速度以及python思维有了很大进步,目前还存在的问题是我认为我的整个框架还没有建立,没有养成先思考再查阅的习惯,导致我遇到问题首先是想着去搜索一下或者询问同学,经过此次学习我更加丰富了我的基础知识,我相信我能够做到独立自主地去探索,我也要感谢帮助我的同学和老师,学习python真的能让我感到快乐!
这篇关于实验1-7的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南