#task1
print('hey, u')
print('hey', ' u')
x = 1
y = 2
z = 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, end=' ')
print()的常用方式:
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, end=' ')
#task2
x,y = eval(input('Enter two numbers: '))
print(f'x = {x}, y = {y}')
x,y = y,x
print(f'x = {x}, y = {y}')
#task3
# 字符编码相关
# chr()返回unicode编码对应的字符 print(chr(10000), end=" ") print(chr(0x025b), end=" ") print(chr(0x2708), end=" ") print(chr(0x00A5), end=" ") print(chr(0x266b))
task4
# 简单的数学计算 from math import sqrt n = float(input('输入一个数:')) x = sqrt(n) print('%f的平方根是: %.2f' %(n, x)) # 输出方式1 print('{}的平方根是{}'.format(n, x)) # 输出方式2 print(f'{n}的平方根是: {x}') # 输出方式3
task5
# 神奇的pi, 与大饼 from math import pi text = ''' 好奇心是人的天性。 理想情况下,学习新东西是让人愉快的事。 但学校里的学习似乎有点像苦役。 有时候,需要画一个大饼,每次吃点学点新鲜的,才会每天变得更好一点点。 ''' print(text) r = float(input('给学习画一个大饼,大饼要做的很大,半径要这么大: ')) circle = 2*pi*r print(f'绕起来,大饼的圆周有这么长, {circle}, 够不够探索宇宙...')