#! /usr/bin/env python3
# -*- coding:utf-8 -*-
#become byte data by encoding of 'utf-8', then to transfer in network.
x="Hello World".encode("utf-8")
print(x) #Result is "b'Hello World'", which became a byte data.
x.decode('utf-8') #become a string date by decoding of 'utf-8' from byte data.
print(x)
sign=input('''Please input
the sign:''')
if sign=='1' :
print("I love %s" % "you")
else :
print("I hate %s %4.2f" % ("you",1314))
print('----------------')
score=input("Please input XiaoMing's score:")
score=float(score)
#String Format Method
print("Score:%10.1f%%\n" % score)
print("Score:{0:15.1f}%\n".format(score))
print(f"Score:{score:20.1f}%\n")
print('-----------')
print('---List---')
classmates=['Jason',123,['XiaoMing','XiaoHuan']]
classmates.append('aaa')
classmates.pop() #delete the end element----'aaa'
print(f'''classmates:{classmates}
{classmates[-1][-1]}''')
print(f"length:{len(classmates)}")
print('---tuple---') # Tuple like array object of java is static and final.
tuple_1=()
tuple_2=(1,)
tuple_3=(1,'2',['123',123])
print(f"tuple_3:{tuple_3}")
print("{0}".format(tuple_3[0]))
print("length:",len(tuple_3))
#小明身高1.75,体重80.5kg。请根据BMI公式(体重除以身高的平方)帮小明计算他的BMI指数,并根据BMI指数:
height=1.75
weight=80.5
bmi=weight/(height**2)
result=''
if bmi>0 and bmi<18.5 :
result='lower';
elif bmi<25 :
result='normal'
elif bmi<28:
result="overweight"
elif bmi<32 :
result="fat";
else :
result="severe obisity"
print(bmi,result)
print('----------')
sum=0
ls=list(range(101)) # The function range is to generate a series number order, which starts from 0 with 1 per step.
for x in ls :
sum+=x
print(f"SUM={sum}")
ls_2=list(range(10))
i=len(ls_2)-1
while i>=0 :
if ls_2[i]==3 :
i-=1
continue
elif ls_2[i]==1 :
break
else :
print(f"{ls_2[i]}")
i-=1
Q.E.D.