20240410

Run Settings
LanguagePython
Language Version
Run Command
""" #any while do loop in python? # can we modify the code? min_length =2 name = input('Please enter your name:') while not(len(name) >= min_length \ and name.isprintable() and name.isalpha()): name = input('Please enter your name:') print('Hello,{0}'.format(name)) """ """ #example 2 a = 0 while a < 10: a += 1 if a % 2: continue # 直接run while 语句 print(a) """ """ l=[1,2,3] val=1 found = False idx=0 while idx < len(l): if l[idx] == val: found = True break #break will exit the whole while block idx += 1 if found: l.append(val) print(l) """ """ #while-else block l= [1,2,3] val=1 idx=0 while idx < len(l): if l[idx] == val: break #break,EXIT退出最近这一层的loop循环. will exit the whole while-else block idx += 1 else: #idx >= len(1)时会执行这个 else block,执行完会exit the whole while-eles block l.append(val) print(l) #The else blcok will not be executed if the loop is stopped by a break statement """ """ #tenary opreator : if a = 1 b=10 if a==1 else 0 print(b) """ """ a = 1 b= a+1 if a==1 else a-1 print(b) # the above blcok is same to below. a=1 if a==1: b= a+1 else: b= a-1 print(b) """ """ a=330 b=330 #print("A") if a > b else print("=") if a == b else print("B") #will excute (if a == b else print("B")) first.从右到左excute (print("A") if a > b else print("=")) if a == b else print("B") """ """ for x in range(6): print(x) else: print("Finally finished") """ """ a=[1,2,3] c=[1,2,3] b=a print(a is b) #is check the address is same or not. print(a is c) #is check the address is same or not. print(a == c) # == check the value is same or not. d=10 print(d == 10) print (d is 10) #check address """ #integer base """ print(int("101",2)) print(int("101",8)) print(type(3+2)) #integer print(type(3**2)) #integer print(type(6/3)) # always float import math x=math.floor(3.999) y=math.floor(-3.15) print(x) print(y) #-4 """ """ import math a=33 b=16 print(a/b) #2.0625 print(a//b) #2 print(math.floor(a/b)) #2 #division operator a//b = math.floor(a/b) only for positive division. a=-33 b=16 print('{0}/{1}={2}'.format(a,b,a/b)) #-2.0625 print('trunc({0}/{1})={2}'.format(a,b,math.trunc(a/b))) #-2 print('{0}//{1} = {2}'.format(a,b,a//b)) #-3 print('floor({0}//{1})={2}'.format(a,b,math.floor(a/b))) #-3 print(a%b) #15 #modulo opeartor : a =b*(a//b)+a%b --> -33 = 16*(-3)+ a%b --> a%b=15 #a%b:a/b的余数 # a//b: a/b的商数 print(a==b*(a//b)+a%b) """ """ x=0.1+0.1+0.1 #0.30000000000000004 y=0.3 print(format(x,'.20f')) print(format(y,'.20f')) print(0.1+0.1+0.1==0.3) #电脑用分数来近似小数,所以存在误差,比如0.125=1/8,0.0625=1/16,所以0.1= 1/16+另一个更小的分数比如1/32 print(0.25+0.25+0.25+0.25) a=10000.1+10000.1+10000.1 b=30000.3 print(format(a,'.20f')) print(format(b,'.20f')) print(10000.1+10000.1+10000.1-30000.3) #3.637978807091713e-12 print(7.1+7.1+7.1==21.3) #False import math print(math.pi) """
Editor Settings
Theme
Key bindings
Full width
Lines