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

Python算术运算符

以下假设变量a为10,变量b为21:

运算符描述实例
+ 加 - 两个对象相加 a + b 输出结果 31
- 减 - 得到负数或是一个数减去另一个数 a - b 输出结果 -11
* 乘 - 两个数相乘或是返回一个被重复若干次的字符串 a * b 输出结果 210
/ 除 - x 除以 y b / a 输出结果 2.1
% 取模 - 返回除法的余数 b % a 输出结果 1
** 幂 - 返回x的y次幂 a**b 为10的21次方
// 取整除 - 返回商的整数部分 9//2 输出结果 4 , 9.0//2.0 输出结果 4.0
原文地址:https://www.cnblogs.com/Mengchangxin/p/9117075.html