python-分⽀语句练习题及答案
@author:⼩魏——
@time:2020-12-29
@content:学习python的练习⽂档
1,注释:解释说明
单⾏注释:#
多⾏注释:'''  """
2,分⽀语句:
if 条件|bool :
执⾏代码1
elif 条件|bool
执⾏代码
else:
执⾏代码2
1. 输⼊⼀个数字三位数判断是否是⽔仙花数
num =int(input("请输⼊成绩:"))
ge = num%10
shi = num//10%10
bai = num//100
if ge**3+shi**3+bai**3==num:
print("是")
else:
print("不是")
2. 做学⽣成绩系统,如果成绩⼤于80分,输出优秀,如果成绩⼤于70分并且⼩于80分,输出良好,如果成绩⼤于60分并且⼩于70分,输出及格,⼩于60分输出不及格。
score =int(input("请输⼊成绩:"))
if100>=score>=0:
if score>=80:
print("优秀")
elif score>=70:
print("良好")
elif score>=60:
print("及格")
else:
print("不及格")
else:
print("⾮法成绩")
3. 输⼊⼀个数,判断它是否能被3、5、7整除,注意考虑同时整除的情况
# n = int(input("请输⼊⼀个数:"))
# if n%3==0 or n%5==0 or n%7==0:
#    print("可以")
# else:
#    print("不可以")
4、打印某年某⽉有多少天。(提⽰:A、闰年的计算⽅法:年数能被4整除,并且不能被100整除;或者能被400整除的整数年份。 B、利⽤%运算可以判断⼀个数能否被另⼀个数整除)
# year = int(input("请输⼊年份:"))
# month = int(input("请输⼊⽉份:"))
#
# if month ==2:
#    #判断是否是闰年
#    if (year%4==0 and year%100!=0) or year%400==0:
#        print(29)
#    else:
#        print(28)
# else:
python新手代码练习#    if month in (1,3,5,7,8,10,12):
#        print(31)
#    else:
#        print(30)
# import calendar
# year = int(input("请输⼊年份:"))
# month = int(input("请输⼊⽉份:"))
#
# if month ==2:
#    #判断是否是闰年
#    if calendar.isleap(year):
#        print(29)
#    else:
#        print(28)
# else:
#    if month in (1,3,5,7,8,10,12):
#        print(31)
#    else:
#        print(30)
5.做学院评奖系统,1)如果数学成绩⼤于80分并且语⽂成绩⼤于80分,获奖学⾦500元。2)如果数学⼩于30并且语⽂⼩于30分,输出重修。
# math = int(input("请输⼊数学成绩:"))
# chinese = int(input("请输⼊语⽂成绩:"))
# if math>=80 and chinese>=80:
#    print("500")
# elif math<30 and chinese<30:
#    print("重修")
6.输⼊三个数,如果其中有⼀个值⼤于1000,则提⽰,输⼊的数值有⼤于1000的。
# a = int(input("请输⼊第⼀个数:"))
# b = int(input("请输⼊第⼆个数:"))
# c = int(input("请输⼊第三个数:"))
#
# if a>1000 or b>1000 or c>1000:
#    print("有⼤于1000的")
# else:
#    print("没有")
7.定义⼀个字符,判断是否为字母。
a=input('输⼊字符:')
print(a.isalpha())
8、定义⼀个整数,计算其平⽅值和⽴⽅值。
# a = int(input("请输⼊⼀个整数:"))
# print(a**2,a**3)
9、定义⼀个⼤写字母,把它转换为⼩写字母后显⽰出来。
a=input('输⼊⼀个⼤写字母:')
print(a.lower())
10、⼀位学⽣参加了三门不同科⽬的考试,计算并显⽰所得的总分和平均分同时显⽰单科所得分数。
math =100
eng =60
chinese =70
print("math:",math)
print("eng:",eng)
print("chinese:",chinese)
print("总分:",math + eng + chinese)
print("平均分:",(math + eng + chinese)/3)
11. 定义三个数a=10,b=20,c=30 a+=10;b-=4; c%=2; 输出a b c 的结果
a =10
b =20
c =30
a +=10
b -=4
c %=2
print(a,b,c)
12.定义三个数,求出其中的最⼤值
# a = int(input("请输⼊第⼀个数:"))
# b = int(input("请输⼊第⼆个数:"))
# c = int(input("请输⼊第三个数:"))
# if a>=b:
#    max = a
# else:
#    max = b
#
# if max<c:
#    max = c
# print(max)
#print("max:",max(a,b,c))
13 如果 score 值⼤于90,则奖励⼀个 Iphone 6s ,当 score 值⼩于等于 90 时,先判断 score 是否⼤于 70 ,如果 score 是介于 70–90 之间,则奖励⼀个红⽶,如果成绩⼩于等于 70 ,则罚做 50 个俯卧撑
score =int(input("请输⼊成绩"))
if score<=70:
print("罚做50个俯卧撑")
elif70<score<=90:
print("奖励⼀个红⽶")
elif score>90:
print("奖励⼀个Iphone6s")
14.对⼀批货物征收税⾦(长整型)。价格在1万元及以上的货物征税5%,在5000元及以上,1万元以下的货物征税3%,在1000元及以上,5000元以下的货物征税2%, 1000元以下的货物免税。编写⼀程序,读⼊货物价格,计算并输出税⾦。
# m = int(input("请输⼊钱数:"))
# if m>=10000:
#    print(m*0.05)
# elif 10000>=m>=5000:
#    print(m * 0.03)
# elif 5000>=m>=1000:
#    print(m * 0.02)
# else:
#    print(0)
15.输⼊3个整数,将其中最⼩的数输出。
a =int(input("请输⼊第⼀个整数"))
b =int(input("请输⼊第⼆个整数"))
c =int(input("请输⼊第三个整数"))
if a>b>c:
print(c)
elif b<a<c:
print(b)
else:
print(a)
print(“min:”,min(a,b,c))
16.某超市为了促销,规定:购物不⾜50元的按原价付款,超过50不⾜100的按九折付款,超过100元的,超过部分按⼋折付款。编⼀程序完成超市的⾃动计费的⼯作。
# m = int(input("请输⼊钱数:"))
# if m>100:
#    print(50+50*0.9+(m-100)*0.8)
# elif 50<m<100:
#    print(50+(m-50)*0.9)
# else:
#    print(m)
17.当前⼩学⽣的成绩单由以前的百分制改为优秀、良好、合格、不合格四个等级的等级制。编⼀程序完成分数的⾃动转换⼯作。转换规则如下: 60分以下的为不合格; 60到69分为合格; 70到89分为良好; 90分以上的为优秀。
score =int(input("请输⼊成绩:"))
if score<60:
print("不合格")
elif60<=score<=69:
print("合格")
elif70<= score <=89:
print("良好")
else:
print("优秀")

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。