python题库刷题训练选择题_python值得学吗

python题库刷题训练选择题_python值得学吗学python嘻嘻,每题第一个是自己的代码,后面的是看见有些好的代码就顺手保存一波了~侵删1916购物1956费马大定理扩展1957幼儿园霸王***********************

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

python嘻嘻,每题第一个是自己的代码,后面的是看见有些好的代码就顺手保存一波了~侵删

 

1916 购物

import math
def isok(X: int,L: int, Z:int)->bool:
    if(Z>=180) : Z = 360 - Z;
    if(5*L*1.0 >= math.pi*Z*X/90) : return True
    return False
T = int(input())
while(T):
    T=T-1
    X, L, Z = map(int, input().split())
    if(isok(X,L,Z)) : print("YES")
    else : print("NO")

 

1956费马大定理扩展

N = int(input())
flag = False
for i in range(2,N+1):
    for j in range(2,i):
        for k in range(j,i):
            for m in range(k,i):
                if(i*i*i==j*j*j+k*k*k+m*m*m):
                    flag = True
                    print("(%d,%d,%d,%d)"%(i,j,k,m))
if(not flag):
    print("OMG")

 

1957幼儿园霸王

n = int(input())
big, small,tmp ="   "
c, k, g, t, v, V =0, 0, 0, 0, 25001, -1
for i in range(n):
    c, k, g, tmp= input().split()
    t = int(c) * int(k) * int(g)
    if(t > V) : V, big = t, tmp
    if(t < v) : v, small =t, tmp
print("%s %s"%(big,small))

*******************

n = int(input())
V, big = -1, ''
v, small = 25001, ''
for i in range(n):
    arr = input().split()
    t = int(arr[0]) * int(arr[1]) * int(arr[2])
    if(t > V) : V, big = t, arr[3]
    if(t < v) : v, small =t, arr[3]
print("%s %s"%(big,small))

********************

def select(L: list())->int:
	return L[4]
n = int(input())
children = list()
for i in range(0,n):
	temp = input().split(' ')
	volume = int(temp[0]) * int(temp[1]) * int(temp[2])
	temp.append(volume)
	children.append(temp)
children.sort(key = select)

print(str(children[n-1][3]) + ' ' + str(children[0][3]))

 

1959好事成双

arr = list(map(int,input().split()))
le = len(arr)
ans = 0
for i in range(le-1):
    for j in range(i, le-1):
        if arr[i]==2*arr[j] or arr[i]*2==arr[j]:
            ans += 1
print(ans)

********************

arr = list(map(int, input().split()))
if arr[-1] == 0:
    arr.pop()
ans = 0
for x in arr:
    ans += arr.count(2 * x)
print(ans)

 

2050年龄段判断

n = int(input())
if n in range(0, 4):
    print("infant")
elif n in range(4, 13):
    print("child")
elif n in range(13,19):
    print("youngster")
else :
    print("youth")

  

2056素数判断

def isprime(n: int)->bool:
    if n==0 or n==1 :
        return False
    i = 2
    while(i*i<=n):
        if(n%i == 0):
            return False
        i += 1
    return True
n = int(input())
if(isprime(n)):
    print("Yes")
else:
    print("No")

 

2057输出最小值

n = int(input())
arr = [int(input()) for i in range(n)]
arr.sort()
print(arr[0])

 

2059斐波那契数

n = int(input())
f = [0]*(n+2)
f[1], f[2] = 1, 1
for i in range(2,n+1):
    f[i] = f[i-1] + f[i-2]
print(f[n])

********************

arr = [0, 1, 1, 2, 3]
n = int(input())
for i in range(5, n + 1):
    arr.append(arr[i - 1] + arr[i - 2])
print(arr[n])

 

2086循环输出

n = int(input())
for i in range(1,n+1):
    print(i)

 

2087循环判断输出

n = int(input())
for i in range(3,n+1):
    if(i%3==0): print(i)

 

2088打印星塔

n = int(input())
for i in range(1,n+1):
    for j in range(1,n-i+1):
        print(' ',end='')
    for j in range(1,2*i):
        print('*',end='')
    print()

 

2090幸运数字

n = input()
if '7' in n:
    print("Yes")
else:
    print("No")

 

2091幸运数字们

L, R = map(int,input().split())
flag = False
for i in range(L,R+1):
    if '7' in str(i):
        flag = True
        print(i)
if not flag:
    print("None")

 

2092翻转数组

n = int(input())
print(n)
a = [int(input()) for i in range(n)]
for i in range(n-1,-1,-1):
    print(a[i])

********************

n = int(input())
arr = [0] * n
for i in range(n):
    arr[i] = int(input())
print(n)
for i in range(1, n + 1):
    print(arr[-i])

 

2093求最值

n = int(input())
a = [int(input()) for i in range(n)]
a.sort()
print("%d %d"%(a[0],a[n-1]))

  

2094前缀和

n = int(input())
print(n)
a, sum = [0]*(n+1), [0]*(n+1)
for i in range(1,n+1):
    a[i] = int(input())
    sum[i] = sum[i-1] + a[i]
    print(sum[i])

 

2101越界了吗

a, b = map(int, input().split())
if a+b>2147483647 or a+b<-2147483648 :
    print("Yes")
else:
    print("No")

  

2102或减与

a, b = map(int, input().split())
print((a|b)-(a&b))

 

2103四舍六入五留双

 这题是个祸害,题目也没说的很清楚

python题库刷题训练选择题_python值得学吗

 

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string f;int d;
    cin>>f>>d;
    
    if(f[d+2]>='6') f[d+1]++;
    else if(f[d+2]=='5')
    {
    	if(f.size()-2>=d) f[d+1]++;
    	else if((f[d+1]-'0')%2==1) f[d+1]++;
    }
    cout<<f.substr(0,2+d);
}

 

2104奇偶性

n = int(input())
if(n%2==0):print(0)
else:print(1)

  

2110求和

n = int(input())
a, sum = 0, 0
for i in range(n):
    s = int(input())
    sum += s
print(sum)

  

2111倒序输出

a, b = map(int, input().split())
for i in range(b, a-1, -1):
    print(i)

  

2112转二进制

n = int(input())
s = bin(n)[2:]
s = s[::-1]
print(s)

  

2118完全平方数

import math
n = int(input())
if ((int(math.sqrt(n)))*(int(math.sqrt(n)))==n):
    print((int(math.sqrt(n))))
else :
    print('No')

  

2119吃龙虾

n, m = map(int, input().split())
sum, t= 0, 0
for i in range(n):
    t = int(input())
    if(t>=m):
        sum += t
print(sum)

 

 

2121转二进制2

n = int(input())
print(bin(n)[2:])

  

2135价钱统计

毒瘤题,需要准确表示四舍五入

网上很多所谓准确解决四舍五入的问题很多都是没卵用

其实加偏置值就行了

from decimal import Decimal
arr = [eval(i) for i in input().split()]
a = 1.2*arr[0]
b = 3.5*arr[1]
c = 4.5*arr[2]
d = 5.0*arr[3]
print('{:.1f}\n{:.1f}\n{:.1f}\n{:.1f}\n{:.1f}\n'.format(Decimal(a+0.005),Decimal(b+0.005),Decimal(c+0.005), Decimal(d+0.005), Decimal(a+b+c+d+0.005)))

********************

a,b,c,d = map(float, input().split())
aa = 1.2 * a
bb = 3.5 * b
cc = 4.5 * c
dd = 5 * d
print(round(aa + 0.01, 1))
print(round(bb + 0.01, 1))
print(round(cc + 0.01, 1))
print(round(dd + 0.01, 1))
print(round(aa+bb+cc+dd + 0.01, 1))

  

 2148字符出现位置

n = int(input())
str = input()
ch = input()
print(str.find(ch[0]))

  

2149字符串出现位置

S = input()
T = input()
print(S.find(T))

  

2153字典序

S = input()
T = input()
flag = S>T
if(flag):
    print('NO')
else:
    print('YES')

  

2393启蒙练习-取余

x, y = map(int, input().split())
print(x%y)

  

2394启蒙练习-四则运算1

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

  

2395启蒙练习-函数1

x = int(input())
print(x*x+x*2+5)

  

2396启蒙练习-圆的面积

PI = 3.14159
r = float(input())
print(PI*r*r)

  

2397启蒙练习-直角三角形

a, b, c = map(int,input().split())
if(a*a+b*b==c*c):
    print(1)
else :
    print(0)

  

2398启蒙练习-数字交换

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

  

2399启蒙练习-条件输出1

a, b = map(int,input().split())
if(a+b>10):
    print(a*b)
else:
    print(a-b)

  

2400启蒙练习-条件输出2

a, b = map(int,input().split())
if(a+b<0):
    print('negative')
elif(a+b>=4):
    print('NO')
else:
    print('YES')

  

2401启蒙练习-首字母

ch = input()
if(ch=='a'):
    print('apple')
elif(ch=='b'):
    print('banana')
elif(ch=='c'):
    print('cat')
else:
    print('no')

  

2402启蒙练习-条件输出3

a, b, c, d = map(int,input().split())
if(a+b>10):
    print(a*b)
elif(b+c>5):
    print(c*d)
elif(d<10 or a*c>100):
    print('Yes')
else:
    print('No')

  

2403启蒙练习-求和

a, b = map(int,input().split())
if(a+b==1):
    print('one')
elif(a+b==2):
    print('two')
elif(a+b==3):
    print('three')
elif(a+b==4):
    print('four')
elif(a+b==5):
    print('five')
elif(a+b==6):
    print('six')
elif(a+b==7):
    print('seven')
elif(a+b==8):
    print('eight')
elif(a+b==9):
    print('nine')
else:
    print('None')

  

2404启蒙练习-2的幂整除

str = bin(int(input()))[2:]
idx = str.rfind('1')
print(len(str)-idx-1)

  

2405启蒙练习-阶乘

n = int(input())
fac = 1
for i in range(1, n+1):
    fac *= i
print(fac)

  

2406启蒙练习-非负数的和

n = int(input())
arr = [int(i) for i in input().split()]
sum = 0
for i in range(n):
    if(arr[i]<0):break
    sum += arr[i]
print(sum)

  

2407启蒙练习-分数求和

N = int(input())
sum = 0.0
for i in range(1,N+1):
    sum += 1.0/i
print(sum)

  

2408启蒙练习-质数判断

import  math
def isprime(n:int)->bool:
    if(n==1 or n==2):
        return False
    for i in range(2, int(math.sqrt(n))+1):
        if(n%i==0):
            return False
    return True
N = int(input())
if(isprime(N)):
    print('yes')
else:
    print('no')

  

2049启蒙练习-倍数的个数

N = int(input())
ret = 0
for i in range(1,N+1):
    if(i%2==0 or i%3==0 or i%5==0):
        ret += 1
print(ret)

  

2410启蒙练习-分数评级

S = int(input())
if(S>=90 and S<=100):
    print('A')
elif(S>=80 and S<90):
    print('B')
elif(S>=70 and S<80):
    print('C')
elif(S>=60 and S<70):
    print('D')
else:
    print('E')

  

2411启蒙练习-数字反写

num = input()
if(num[3]=='0'):
    num = num[0:3]
    if(num[2]=='0'):
        num = num[0:2]
        if(num[1]=='0'):
            num = num[0:1]
print(num[::-1])

********************

n = int(input())
print(int(str(n)[::-1]))

  

2412启蒙练习-九九乘法表

n = int(input())
for i in range(1,n+1):
    for j in range(1, i+1):
        print('%d*%d=%d'%(j, i, j*i), end='')
        if(j == i):
            print()
        else:
            print(' ',end='')

  

2413启蒙练习-图形输出1

n = int(input())
for i in range(1,n+1):
    print(i*'*')

  

2414启蒙练习-图形输出2

n = int(input())
for i in range(1,n+1):
    print((2*i-1)*'*')

  

2415启蒙练习-分数求和2

n = int(input())
sum = 0.0
for i in range(1,n+1):
    if(i%2==1):
        sum += 1.0/i
    else:
        sum += -1.0/i
print(sum)

  

2416启蒙练习-9的个数

n = int(input())
sum = 0
for i in range(1, n+1):
    sum += str(i).count('9')
print(sum)

  

2417启蒙练习-分数求和3

fac = [1, 1, 1*2, 1*2*3, 1*2*3*4, 1*2*3*4*5, 1*2*3*4*5*6, 1*2*3*4*5*6*7, 1*2*3*4*5*6*7*8, 1*2*3*4*5*6*7*8*9, 1*2*3*4*5*6*7*8*9*10]
n = int(input())
sum = 0.0
for i in range(1, n+1):
    sum += 1.0/fac[i]
print(sum)

  

2418启蒙练习-最大的质数

import  math
def isprime(n:int)->bool:
    if(n==1 or n==2):
        return False
    for i in range(2, int(math.sqrt(n))+1):
        if(n%i==0):
            return False
    return True
n = int(input())
for i in range(n-1,1,-1):
    if(isprime(i)):
        print(i)
        exit(0)

  

2419启蒙练习-回文数

n = input()
l = len(n)
for i in range(l):
    if(n[i]!=n[-(i+1)]):
        print('no')
        exit(0)
print('yes')

********************

n = input()
s = n[::-1]
if n == s:
    print('yes')
else:
    print('no')

  

2420启蒙练习-正数的和

n = int(input())
arr = [int(i) for i in input().split()]
sum = 0
for i in range(n):
    if(arr[i]>0):
        sum += arr[i]
print(sum)

  

2578启蒙练习-鸡兔同笼

n, m = map(int, input().split())
b = (m-2*n)//2
a = n - b
print(a, b)

  

2579启蒙练习-跑步问题

n, a, b = map(int, input().split())
print(n*(a+b)//(2*a*b), n*(a-b)//(2*a*b))

  

2580启蒙练习-复读机

print(input())

 

2581启蒙练习-量身高

print('My height is %dcm.'%(int(input())))

  

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/166387.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号