1. 程式人生 > 其它 >實驗一:

實驗一:



task1_1.py
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.py

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))

 

task1_3.py
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*'=')


task2_1.py

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.py

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

task3.py

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.py

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 = " ")

task5_1.py

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.py

from math import pi
text = '''
   好奇心是人的天性。
   理想情況下,學習新東西是讓人愉快的事。
   但學校裡的學習似乎有點像苦役。
   有時候,需要畫一個大餅,每次嘗試學一些新鮮的,才會每天變得更好一點點。
   '''
print(text)
r = float(input('給學習畫一個大餅,大餅要做的很大,半徑要這麼大: '))
circle = 2*pi*r
print(f'繞起來,大餅的圓周有這麼長, {circle}, 夠不夠激發你探索未知的動力...')