Python实现比较有意思的玩意儿

闲来无事,使用Python写一点小玩的代码

现有a = 1, b = 2, (a and b) 和 (a or b) 分别返回什么? 为什么?

	#a and b   --->   2    同真则返回最后一个真值
	#a or b    --->   1    返回第一个真值	

  1. 编写一个程序计算个人所得税(以下为个人所得税税率表,3500元起征):

    应纳税所得额(含税)                        税率(%)
    不超过1500元的                              3
    超过1500元至4,500元的部分                   10
    超过4,500元至9,000元的部分                  20
    超过9,000元至35,000元的部分                 25
    超过35,000元至55,000元的部分                30
    超过55,000元至80,000元的部分                35
    超过80,000元的部分                          45
# coding=utf-8
salary = input("输入您的月薪:")
temp = int(salary) - 3500
if temp <= 0:
 print("elif 0 < temp < 1500:您的月薪为%d元不需要纳税"%int(salary))
elif 0 < temp <= 1500:
 tax = temp*0.03
elif 1500 < temp <= 4500:
 tax = (temp - 1500)*0.1 + 45    
 #1500*0.03
elif 4500 < temp <= 9000:
 tax = (temp - 4500)*0.2 + 345   
 #1500*0.03+(4500-1500)*0.1
elif 9000 < temp <= 35000:
 tax = (temp - 9000)*0.25 + 1245 
 #1500*0.03+(4500-1500)*0.1+(9000-4500)*0.2
elif 35000 < temp <= 55000:
 tax = (temp - 35000)*0.3 + 7745 
 #1500*0.03+(4500-1500)*0.1+(9000-4500)*0.2+(35000-9000)*0.25
elif 55000 < temp <= 80000:
 tax = (temp - 55000)*0.35 + 13745   
 #1500*0.03+(4500-1500)*0.1+(9000-4500)*0.2+(35000-9000)*0.25+(55000-35000)*0.3
elif temp > 80000:
 tax = (temp - 80000)*0.45 + 22495   
 #1500*0.03+(4500-1500)*0.1+(9000-4500)*0.2+(35000-9000)*0.25+(55000-35000)*0.3+(80000-55000)*0.35
print("您的月薪为%d元,应纳税额%d元"%(int(salary),tax))
  1. 使用while,完成以下图形的输出
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *
i=1
while i <= 9:
    if i<=5:
        print(' '*(5-i),'*'*(2*i-1))
    else:
        print(' '*(i-5), '*'*(2*(10-i)-1))
    i+=1


  使用while、if来完成剪刀石头布程序,要求,当玩家第3次获胜时才退出游戏,否则继续玩

# coding=utf-8
import random
# 获胜次数
win_times = 0
while win_times <= 2:
  player = input('请输入:剪刀(0)  石头(1)  布(2):')
  player = int(player)
  computer = random.randint(0,2)

  if ((player == 0) and (computer == 2)) or ((player ==1) and (computer == 0)) or ((player == 2) and (computer == 1)):
      win_times += 1
      print('获胜,哈哈,你太厉害了')
  elif player == computer:
      print('平局,要不再来一局')
  else:
      print('输了,不要走,洗洗手接着来,决战到天亮')


python实现99乘法表

i = 1

while i <= 9:  # 控制行数

    j = 1
    while j <= i:  # 控制每行显示 内容的个数
        print("%d*%d=%d\t" % (j, i, j*i), end="")
        j += 1

    print("")

    i += 1


你可能感兴趣的:(Python实现比较有意思的玩意儿)