python入门第二天__练习题

1、Python 数字求和

 1 #!/usr/bin/python3
 2 # -*- coding: UTF-8 -*-
 3 
 4 import sys
 5 
 6 num_a=int(input("请输入第一个整数:"))
 7 num_b=int(input("请输入第二个整数:"))
 8 
 9 print("{0}+{1}={2}".format(num_a,num_b,num_a+num_b))
10 
11 
12 
13 14 #sys.stdout.write()输出对象必须是字符
15 sys.stdout.write(str(num_a+num_b))

结果输出:

================= RESTART: F:/python从入门到放弃/5.31/continue.py =================
请输入第一个整数:59
请输入第二个整数:61
59+61=120
120
>>> 

2、9*9乘法表

 1 #!/usr/bin/python3
 2 # -*- coding: UTF-8 -*-
 3 
 4 
 5 num_row=1
 6 while num_row<=9:
 7     
 8     num_column=1
 9     while num_column<=num_row:
10         print("{0}x{1}={2}".format(num_column,num_row,num_row*num_column),end='\t')
11         num_column+=1
12 
13     num_row+=1
14     print()
15 
16 print("END")
17     

结果输出:

===
1x1=1    
1x2=2    2x2=4    
1x3=3    2x3=6    3x3=9    
1x4=4    2x4=8    3x4=12    4x4=16    
1x5=5    2x5=10    3x5=15    4x5=20    5x5=25    
1x6=6    2x6=12    3x6=18    4x6=24    5x6=30    6x6=36    
1x7=7    2x7=14    3x7=21    4x7=28    5x7=35    6x7=42    7x7=49    
1x8=8    2x8=16    3x8=24    4x8=32    5x8=40    6x8=48    7x8=56    8x8=64    
1x9=9    2x9=18    3x9=27    4x9=36    5x9=45    6x9=54    7x9=63    8x9=72    9x9=81    
END

猜你喜欢

转载自www.cnblogs.com/Mengchangxin/p/9117075.html