计蒜客python答案Top50

新手小白入门刷题学习,前50道题目,巩固基础,有些题目的解答并不是最简单而又高效,纯属暴力破解,希望各位大佬多多指教!
计蒜客官网: https://www.jisuanke.com

在这里插入图片描述

T1001 计算A+B(新手教程)

A,B=map(int,input().split())
print(A+B)

提示: map是python内置函数,会根据提供的函数对指定的序列做映射。split()函数默认空格分隔

T1002 输出马里奥

s='''        ********
       ************
       ####....#.
     #..###.....##....
     ###.......######
        ...........
       ##*#######
    ####*******######
   ...#***.****.*###....
   ....**********##.....
   ....****    *****....
     ####        ####
   ######        ######'''
print(s)

T1003 输出字符菱形

s = input()
ls=[1,3,5,3,1]
for i in ls:
    print((s*i).center(5))

提示: center(width)函数,长度为width,字符串居中;ljust左对齐,rjust右对齐

T1004 输出Hello, World!

print("Hello, World!")

T1005 输出字符三角形

s = input()
ls=[1,3,5]
for i in ls:
    print((s*i).center(5))

T1006 对齐输出

a,b,c=map(int,input().split())
print("{:>8} {:>8} {:>8}".format(a,b,c))

提示: 宽度为8个字符,>表示右对齐,^表示居中对齐,<表示左对齐

T1007 整型与布尔型的转换

b = int(input())
print(int(bool(b)))

T1008 打印字符

a = int(input())
b=chr(a)
print(b)

提示: chr()函数,返回单个ascii值(0-255)的字符;ord()函数正好相反

T1009 等差数列末项计算

a,b,n=map(int,input().split())
d=b-a
c=a+(n-1)*d
print(c)

提示: 高中数学必修n中的,等差数列通项公式:an = a1 + (n-1)d , 其中 a1为首项,d为公差

T1010 计算线段长度

x1,x2=map(float,input().split())
y1,y2=map(float,input().split())
length = pow(pow((x1-y1),2)+pow((x2-y2),2),0.5)
print("{:.3f}".format(length))

提示: 考察pow函数(x,y)表示:x的y次方 , {:.3f} 表示保留小数点后三位

T1011 反向输出一个三位数

n = int(input())
a=n//100
b=n//10%10
c=n%10
print("{:d}{:d}{:d}".format(c,b,a))

提示点: 本题类似于求水仙花数,分别取出个,十,百,位即可,注意:在python中 //表示整除,/表示除

T1012 A*B问题

a,b=map(int,input().split())
print(a*b)

T1013 输出第二个整数

a,b,c=input().split()
a,b,c=int(a),int(b),int(c)
print(b)

T1014 输出保留3位小数的浮点数

n = float(input())
print("{:.3f}".format(n))

T1015 输出保留12位小数的浮点数

x = float(input())
print("{:.12f}".format(x))

T1016 打印ASCII码

a = ord(input())
print(a)

T1017 计算(a+b)*c的值

a,b,c=map(int,input().split())
print((a+b)*c)

T1018 计算(a+b)/c的值

a,b,c = map(int,input().split())
if c!=0:
     d=int((a+b)/c)
     print("{:d}".format(d))

T1019 带余除法

a,b=input().split()
a,b=eval(a),eval(b)
c=int(a/b)
d=int(a-c*b)
print("{:d} {:d}".format(c,d))

T1020 计算分数的浮点数值

a,b = map(int,input().split())
c=float(a/b)
print("{:.9f}".format(c))

T1021 甲流疫情死亡率

a,b=map(int,input().split())
c=float(b/a)*100
print("{:.3f}%".format(c))

提示: 注意强制转换类型

T1022 计算多项式的值

x,a,b,c,d = map(float,input().split())
e=a*pow(x,3)+b*x*x+c*x+d
print("{:.7f}".format(e))

T1023 温度表达转化

F = float(input())
C = float(5*(F-32)/9)
print("{:.5f}".format(C))

T1024 与圆相关的计算

r = float(input())
d=2*r
c=2*3.14159*r
a=r*3.14159*r
print("{:.4f} {:.4f} {:.4f} ".format(d,c,a))

T1025 计算浮点数相除的余数

a,b=map(float,input().split())
e=int(a/b)
n=a-e*b
print("{:.6f}".format(n))

提示: 两数相除后取整,前面要加强制转换类型,不然会报错。

T1026 计算球的体积

r = float(input())
v=float((4*3.14*pow(r,3))/3)
print("{:.2f}".format(v))

T1027 大象喝水

h,r=map(int,input().split())
v=h*r*r*3.14159
n=int(20000/v+1)
print("{:d}".format(n))

T1028 苹果和虫子

n,x,y = map(int,input().split())
d = n-(int((y/x))+1)
print("{:d}".format(d))

提示: 本题须注意苹果的完整性,即使被咬一口,也不能算完整的一个,所以要+1

T1029 计算2的幂

a=int(input())
b=pow(2,a)
print(int(b))

T1030 判断数正负

n = int(input())
if(n>0):
    print("positive")
if(n==0):
    print("zero")
if(n<0):
    print("negative")

T1031 输出绝对值

n = float(input())
a = abs(n)
print("{:.2f}".format(a))

提示: 运用abs()绝对值函数即可

T1032 奇偶数判断

n = int(input())
if(n%2==0):
    print("even")
else:
    print("odd")

T1033 奇偶ASCII值判断

b = ord(input())
if(b%2!=0):
    print("YES")
else:
    print("NO")

T1034 整数大小比较

x,y = map(int,input().split())
if(x>y):
    print(">")
elif(x<y):
    print("<")
elif(x==y):
    print("=")

T1035 判断是否为两位数

a = int(input())
if(10<=a<=99):
    print("1")
else:
    print("0")

T1036 收集瓶盖赢大奖

a,b = map(int,input().split())
if(a>=10 or b>=20):
    print("1")
else:
    print("0")

T1037 判断一个数能否同时被3和5整除

n = int(input())
if(n%3==0 and n%5==0):
    print("YES")
else:
    print("NO")

T1038 判断能否被3,5,7整除

x = int(input())
if(x%105==0):
    print(3,5,7)
elif(x%35==0):  
    print(5,7)
elif(x%21==0):  
    print(3,7)
elif(x%15==0):
    print(3,5)
elif(x%7==0):
    print(7)
elif(x%5==0):
    print(5)
elif(x%3==0):
    print(3)
elif(x%3!=0 and x%5!=0 and x%7!=0):
    print("n")

T1039 小蒜蒜的成绩

a,b = map(int,input().split())
if(a<60 and b>=60) or (a>=60 and b<60):
    print("1")
else:
    print("0")

T1040 蒜头君赴约会

a = int(input())
if(a==1):
    print("NO")
if(a==2):
    print("YES")
if(a==3):
    print("NO")
if(a==4):
    print("YES")
if(a==5):
    print("NO")
if(a==6):
    print("YES")
if(a==7):
    print("YES")

T1041 蒜头君上班

a =eval(input())
b = 50 + a/3
c = a/1.2
if(c>b):
    print("Bike")
if(c<b):
    print("Walk")
if(c==b):
    print("All")
    

T1042 分段函数

x = float(input())
if(0<=x<5):
    a=-x+2.5
    print("{:.3f}".format(a))
elif(5<=x<10):
    a=2-1.5*(x-3)*(x-3)
    print("{:.3f}".format(a))
elif(10<=x<20):
    a=x/2-1.5
    print("{:.3f}".format(a))

T1043 计算邮资

a,b = map(str,input().split())
a=eval(a)
c=0
if(b=="y"):
    if(a<=1000):
        c=8+5
    else:
        c=8+(int((a-1000)/500)+1)*4+5
elif(b=="n"):
   if(a<=1000):
        c=8
   else:
        c=8+(int((a-1000)/500)+1)*4
print(c)

T1044 最大数输出

a,b,c = map(int,input().split())
d = max(a,b,c)
print(d)

T1045 三角形判断

a,b,c=map(int,input().split())
if(a+b>c and a+c>b and b+c>a):
    print("yes")
else:
    print("no")

T1046 判断闰年

a=eval(input())
if(a%100!=0 and a%4==0) or (a%400==0):
     print("Y")
else:
    print("N")

T1047 点和正方形的关系

x,y = map(int,input().split())
if(-1<=x<=1 and -1<=y<=1):
    print("yes")
else:
    print("no")

T1048 简单计算器

a,b,c1 = map(str,input().split())
a,b=eval(a),eval(b)
if(c1=="+"):
    print(a+b)
if(c1=="-"):
    print(a-b)
if(c1=="*"):
    print(a*b)
if(c1=="/" and b==0):
    print("Divided by zero!")
if(c1=="/" and b!=0):
    print(int(a/b))
if(c1!='+' and c1!='-' and c1!='*' and c1!='/'):
    print("Invalid operator!")

T1049 苹果和虫子2

import math
n,x,y = map(int,input().split())
a=n-int(math.ceil(y/x))
if(a>=0):
    print(a)
else:
    print("0")

提示: 运用ceil()函数向下取整

T1050 求平均年龄

n = eval(input())
ls =[]
for i in range(n):
    ls.append(eval(input()))
print("{:.2f}".format(sum(ls)/n))

这是up刚入门时刷的题目,难度不大,部分题目即使过了测试,但还是存在bug,接下来会更新新的解法,如果题解有问题或者您有更好的解法,欢迎一起来探讨python语言学习,加油!

祝君: " 百尺竿头 , 更进一步 !"

  • 18
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值