1 a=5; 2 b=2; 3 print(a+b);#result:7 desc:加 4 print(a-b);#result:3 desc:減 5 print(a*b);#result:10 desc:乘 6 print(b**10);#result:1024 desc:冪 7 print(a/b);#result:2.5 desc:除 8 print(a//b);#result:2 desc:取整除 9 print(a%b);#result:1 desc:取餘 10 11 print(not True);#false desc:對應java中 ! 12 print(True and False);#false desc:對應java中 && 13 print(True or False);#true desc:對應java中 ||
1 num_1 = int(input()); 2 num_2 = int(input()); 3 num_3 = int(input()); 4 max_num = 0; 5 if num_1 > num_2: 6 max_num = num_1; 7 else: 8 max_num = num_2; 9 if max_num < num_3: 10 max_num = num_3 11 print(max_num);
1 true_num = '45'; 2 while True: 3 input_num = input("input a num:"); 4 if input_num == true_num: 5 print("猜數字成功!"); 6 break;
1 i = 1; 2 while i <= 9: 3 j = 1; 4 while j <= i: 5 print(str(j) + "*" + str(i) + "="+ str(i*j),end=" "); 6 j+=1; 7 i += 1; 8 print();
1 height = 10; 2 i = 1; 3 while i <= height: 4 j = 1; 5 while j <= i: 6 print("*",end="") 7 j += 1; 8 i += 1; 9 print();