python

1.判断一个数,是否是2的指数

       2的指数

              0000 0010     0000 0001

              0000 0100     0000 0011

              0000 1000     0000 0111

              0001 0000     0000 1111

       提示:所有2的指数:n&(n - 1) == 0

num = int(input("请输入一个数:"))
if num & (num - 1) == 0:
	print(" %s 是2的指数"%(num))
else:
	print(" %s 不是2的指数"%(num))

 

2.给定成绩,判断用户成绩的档次

       100:提示满分

       90~100:优秀

       80~100:良好

       70~80:还可以,多多努力

       60~70:合格

       0~60:不合格

       0:鸡蛋

score = int(input("请输入你的成绩:"))
if score == 100:
	print(" 满分,非常优秀")
elif score >= 90 and score < 100:
	print("优秀")
elif score >= 80 and score < 90:
	print("良好")
elif score >= 70 and score < 80:
	print("还可以,多多努力")
elif score >= 60 and score < 70:
	print("及格")
elif score < 60 and score >0:
	print("不合格")
elif score == 0:
	print("鸡蛋")
	

 

3.下列哪一项是“4是奇数或-9为正数”的否定( C)

       A、4是偶数或-9不是负数

       B、4是奇数或-9不是负数

       C、4是偶数和-9是负数

       D、4是奇数和-9不是负数

4.如果A是“10110110”,B是“11100000”,C是“10100000”,下面成立的是( D)

       A、 C=A|B

       B、  C=~A

       C、 C=~B

       D、 C=A&B

D.10110110    A.  10110110       B.10110110    C. 11100000

   11100000          11100000           01001001        00011111

   10100000         11110110

5.判断一个整数是奇数还是偶数,至少有两种方式实现(位运算已经讲解的话)

num = int(input("请输入一个数:"))
#方法一
# if num % 2 == 0:
# 	print(f"{num}是偶数")
# else:
# 	print(f"{num}是奇数")
#方法二
if num & 1 == 0:
	print("{}是偶数".format(num))
elif num & 1 == 1:
	print("{}是奇数".format(num))

 

6.求矩形的面积和周长

a = int(input("请输入矩形的长:"))
b = int(input("请输入矩形的宽:"))
#矩形的周长
l = (a + b)*2
#矩形的面积
s = a * b
print("矩形的周长为:",l,"矩形的面积为:",s)

 

7.根据天数(从控制台上输入)计算周数和剩余的天数

days = int(input("请输入数字:"))
mouth = 30
if days == 1:
	print("这个月的第一天,新的开始,还剩下%s" %(mouth - days) +"天,打起精神")
elif days <=7:
	print("这个月的第一周,还剩下%s"%(mouth - days) +"天,加油哦")
elif days <=14:
	print("这个月的第二周,还剩下%s"%(mouth - days) +"天,要继续加油哦")
elif days <=21:
	print("这个月的第三周,还剩下%s"%(mouth - days) +"天,要坚持哦")
elif days <=28:
	print("这个月的第四周,还剩下%s"%(mouth - days) +"天,要加油哦")
elif days <=30:
	print("已经是新的一周了,你有坚持吗?这个月还剩下%s"%(mouth - days) +"天,加油哦")
else:
    print("这一个月已经完了,下个月已经开始了")

 

8. 根据已知圆的半径radius(从控制台上输入),求其面积和周长(PI可以使用math.pi,也可以使用3.14)

radius = int(input("请输入圆的半径:"))
PI = 3.14
l = 2 * radius * PI
s = PI * radius **2
print("圆的面积为%s"% s,"圆的周长为%s"% l)

 

9.输入一个年份,判断该年是否是闰年

year = int(input("请输入年份:"))
if year % 400 == 0 or year % 4 == 0 or year % 100 != 0:
	print("%s是闰年"% year)
else:
	print("%s不是闰年"% year)

 

10.输入赵本山的考试成绩,显示所获奖励

       成绩==100分,爸爸给他买辆车

       成绩>=90分,妈妈给他买MP4

       90分>成绩>=60分,妈妈给他买本参考书

       成绩<60分,什么都不买

score = int(input("请输入赵本山的成绩:"))
if score == 100:
	print("爸爸给他买辆车")
elif score >=90:
	print("妈妈给他买MP4")
elif score < 90 and score >= 60:
	print("妈妈给买本参考书")
elif score < 60:
	print("什么都不买")

 

11.计算器:

       请输入两个数和一个符号,完成两个数的+ - * / %  // **

a = int(input("请输入一个数:"))
b = int(input("请输入另一个数:"))
addition = a + b
subtraction =a - b
multiplication =a * b
division =a / b
zhengchu = a // b
yushu = a % b
mi = a ** b
print("第一个数加第二数的结果为:%s"% addition)
print("第一个数减第二数的结果为:%s"% subtraction)
print("第一个数乘第二数的结果为:%s"% multiplication)
print("第一个数除第二数的结果为:%s"% division)
print("第一个数整除第二数的结果为:%s"% zhengchu)
print("第一个数除第二数的余数为:%s"% yushu)
print("第一个数的第二数的次方为:%s"% mi)

 

12.

       健康计划

       用户输入身高(m),体重(kg)

       计算公式:BMI = 体重 / 身高^2

              BMI < 18.5:过轻

              18.5≤ BMI <24:正常

              24 ≤ BMI <27:过重

              27 ≤ BMI < 30:轻度肥胖

              30 ≤ BMI < 35:中度肥胖

              BMI ≥ 35:重度肥胖

m = float(input("请输入你的身高:"))
n = float(input("请输入你的体重:"))
BMI = n / m**2
if BMI < 18.5:
	print("过轻")
elif BMI >=18.5 and BMI < 24:
	print("正常")
elif BMI >=24 and BMI < 27:
	print("过重")
elif BMI >= 27 and BMI < 30:
	print("轻度肥胖")
elif BMI >=30 and BMI < 35:
	print("重度肥胖")
elif BMI >=35:
	print("重度肥胖")

 

13.设计一个程序,完成(英雄)商品的购买(界面就是第一天打印的界面)

              展示商品信息(折扣)->输入商品价格->输入购买数量->提示付款

              输入付款金额->打印购买小票(扩展)

print("\n\t\t\t\t英雄商城英雄列表\n")
print("~*"*40)
print("\n编号\t姓名\t昵称\t价格\t库存\t描述\n")
print("1\t纳尔  迷失之牙  3500\t100\t丛林不会原谅盲目与无知\n")
print("2\t锐雯  放逐之刃  4000\t100\t她是残忍高效的战士\n")
print("3\t薇恩  暗夜猎手  3500\t100\t这个世界不想人们想象的那么美好\n")
print("4\t扎克  生化魔人  3000\t100\t即使你没有脊柱,你也必须站起来\n")
print("5\t杰斯 未来守护者 2500\t100\t武装着睿智与魅力,你的选择没有错\n")
print("~*"*40)
choice = input("\n(温馨提示)请输入您要购买的英雄编号:")
if choice == "1":
 print("\n\t\t\t\t英雄商城购买英雄\n")
 print("英雄购买票据\n")
 print("~*"*40)
 print("\n\t英雄名称:纳尔(喳喳)\n")
 print("\n\t英雄属性:生命值428(+85)/能量值200(+0)/移动速度425/攻击力55.8(+3.2)\n")
 print("\n\t\t攻击速度0.651(+3.1%)/护甲值24(+1.25)/攻击距离125\n\n")
 print("\n\t英雄座右铭:一人之行可灭世,众人之勤可救世!\n")
 print("\n\t英雄名称:纳尔(喳喳)\n")
 print("\n\t英雄价格:3000\n")
 print("\n\t活动折扣:9.5\n\n")
 print("插播广告:当风云变色,当流离失所,世界不再是旧日模样\n")
 print("你是否会为了自己的梦想战斗,直至力战身亡,直至彼岸他乡\n")
 print("~*"*40)
 price  = int(input("\n请输入商品价格:"))
 if price == 2850:
  number = int(input("\n请输入购买数量"))
  payment = price*number
  print("\n请付款:"+"%s"%(payment)+" 元")
  actual_payment = int(input("\n"))
  if actual_payment >= payment:
   input("\n按任意键打印小票")
   print("\n\t\t\t\t英雄商城购买英雄\n")
   print("英雄购买票据\n")
   print("~*"*40)
   print("\n\t英雄名称:纳尔(喳喳)\n")
   print("\t英雄价格:3000\n")
   print("\t活动折扣:9.5\n\n")
   print("\t应付付款:"+"%s"%(payment)+" 元\n")
   print("\t实际付款:"+"%s"%(actual_payment)+" 元\n")
   print("\t找零:"+"%s"%(actual_payment-payment)+" 元\n")
   print("插入广告:当风云变色,当流离失所,世界不再是旧日模样\n")
   print("你是否会为了自己的梦想战斗,直至力战身亡,直至彼岸他乡\n")
   print("~*"*40)
  else:
   print("\n你的钱不够哦,要理性哦")
 else:
  print("价格有误")
else:
 print("\n暂未开放购买")

 

 

 

 

14.输入三边的长度,求三角形的面积和周长(海伦公式)

import math
a = int(input("请输入一边边长:"))
b = int(input("请输入一边边长:"))
c = int(input("请输入一边边长:"))
if a + b > c and a + c > b and b + c >a :
	print("此三角形成立")
else:
	print("请重新输入")
l = a + b + c
p = l / 2
n = p * (p - a)*(p - b)*(p - c)
s = math.sqrt(n)
print("次三角形的周长为:%s"% l)
print("此三角形的面积为:%s"% s)

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值