首页 > 其他分享 >pta lab

pta lab

时间:2022-11-29 03:44:16浏览次数:29  
标签:num1 int pta else lab str print input

pta python lab

汪汪队,熬大夜

1.

str1 = input()
str2 = ""
if str1=='':
    print('NULL')
else:
    for v in str1:
        # F-Z 直接减小5
        if 'Z' >= v >= 'F':
            str2 += (chr(ord(v) - 5))
        # A-E 减小5位之后的ascii码不是字母,所以添加26位减5=加21
        elif 'E' >= v >= 'A':
            str2 += (chr(ord(v) + 21))
        #其他的原样输出
        else:
            str2 += str(v)
    print(str2)

2.

x=float(input())
if x<3:
    # format(x,'.2f') 保留两位小数
    print('f('+str(format(x,'.2f'))+')=1.20')
elif 3==x:
    print('f('+str(format(x,'.2f'))+')=10.00')
else:
    print('f('+str(format(x,'.2f'))+')='+str(2*x+1))

3.

import math
r=float(input())
print(format(math.pi*r*r,'.2f'))

4.

num1 = input()
num2 = input()
sum = ''

#算出最长字符串长度
if len(num1) < len(num2):
    maxLen = len(num2)
else:
    maxLen = len(num1)

# 将两个字符串反转,便于计算
num1 = ''.join(reversed(num1))
num2 = ''.join(reversed(num2))

# 用t统计是否进位
t = 0
# 123
# 789
for i in range(maxLen):
    # tmp记录同位相加结果

    # 如果num1和num2都没被读取完全
    if len(num1) > i and len(num2) > i:
        tmp = int(num1[i]) + int(num2[i]) + t
    # 如果num2被读完了
    elif len(num1) > i:
        tmp = int(num1[i]) + t
    # 如果num1被读完了
    elif len(num2) > i:
        tmp = int(num2[i]) + t

    # 用t统计是否进位
    t = int(tmp / 10)
    # sum追加个位部分
    sum += str(tmp % 10)

#如果最后余数为1,加上
if 1==t:
    sum+='1'
#将结果反转
print(''.join(reversed(sum)))
# 相同位置运算结束,计算不同位
#       123
# 45    678

5.

x=input().split(' ')

money=float(x[0])
year=int(x[1])
rate=float(x[2])

print('interest='+format(money*(1+rate)**year-money,'.2f'))

6.

x=int(input())
if 0==x%2:
    print(str(x)+'是偶数')
else:
    print(str(x)+'不是偶数')

7.

i=1
while i > 0:
    i+=1
    if 1==i%5:
        if 5==i%6:
            if 4==i%7:
                if 10==i%11:
                    print(i)
                    break

8.

x=input()
print('hello,'+x)

9.

x=0

#总人数
total_count=0
#没及格人数
count=0
#总分
sum=0
while x>=0:
    x=int(input())
    if x>0:
        sum+=x
        total_count+=1
        if x<60:
            count+=1
if total_count!=0:
    print('平均分='+format(sum/total_count,'.2f')+',不及格人数='+str(count))
else:
    print('没有学生')

10.

str=input()
x=int(input())
y=int(input())

if x<1 or y>len(str)+1 or x>=y:
    print('没子串!')
else:
    print(str[x-1:y])

11.

str1=input()
x=input()
count=1

#b记录是否找到
b=True

for v in str1:
    if v==x:
        print('index='+str(count))
        b=False
        break
        
    count+=1
if b :
    print("can't find letter",x)
    

12.(不完整)

s=input().split(' ')

if str.isdigit(s[0]) and str.isdigit(s[1]):
    x=int(s[0])
    y=int(s[1])
    if x<0 or y<0:
        print('不能负数')
    else:
        #p,q 分子,分母
        p=1
        q=1

        for i in range(0,x):
            p*=(y-i)

        for i in range(1,x+1):
            q*=i


        print('result='+format(p/q,'.2f'))
else:
    print('请输入数值')

13.

x = int(input())

if 2 == x:
    print(str(x), 'is prime')
elif x < 2:
    print(str(x), 'is not prime')
else:
    b = True
    for i in range(2, x):
        if x % i == 0:
            print(str(x), 'is not prime')
            b = False
            break

    if b:
        print(str(x), 'is prime')

14.(未完成)

x=input().split(' ')
s=''

for v in x:
    f=float(v)
    if f<5000:
        s+=str(f*15)
    else:
        s+=str(f)
    s+=' '

print(s.split(' '))

15.(未完成)


16.

import math
#创建判断是否为数字的函数,如果是,则返回true
def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass

x=input()

if is_number(x):
    n=float(x)
    if n>0:
        print('f('+str(format(n,'.2f'))+') =',format(math.cos(n)+math.e**n,'.2f'))
    else:
        print('f('+str(format(n,'.2f'))+') = 0.00')
        
else:print('Input Error')

17.

import math 

def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass

x=input()

if is_number(x):
    n=float(x)
    if n>0:
        print('f('+str(format(n,'.2f')+') = '+format(math.log(n,math.e)+math.pow(n,0.5),'.2f')))
    else:
        print('f('+str(format(n,'.2f')+') = 0.00'))
else:
    print('Input Error')

18.

#创建字典m
m={}

while True:
    s=input()
    #如果输入为回车,则退出
    if s=='':
        break
    else:
        kv=s.split(':')
        m[kv[0]]=kv[1]

course=input('请输入要查询的课程:\n')

#获取课程分数
if None==m.get(course):
    print('没有该门课程')
else:
    print(m.get(course))

19.

s=input().split(',')
x=int(s[0])
y=int(s[1])

if x<60 or y<60:
    print('不合格')
elif (x+y)/2>=90:
    print('成绩优秀')
else:
    print('通过')

20.(未完成)


21.

print('Life is short,I want to learn python!')

22.

s=input()
x=int(input())

for i in range(0,x):
    print(s,end='! ')

23.

x=input()

if 'a'<=x<='z':
    print(chr(ord(x)-32))
else:
    print(x)

24.

Ctrl + c
Ctrl + v

25.

s=input()
l=len(s)-1
b=True

for i in range(0,int(l/2)+1):
    if s[i]!=s[l-i]:
        print('no')
        b=False  
        break

if b :
    print('yes')

26.(未完成)

import random

x=random.randint(0,100)
#是否猜中
no_guess=True

for i in range(0,8):
    n=int(input())
    if n>x:
        print('Too big')
    elif n<x:
        print('Too small')
    else:
        print('Luck You!')
        no_guess=False
        break

if no_guess:
    print('Game Over!')

27.

print('我要学Python')

28.

x=input().replace(' ','').replace('[','').replace(']','').replace('\'','').split(',')
s=''
for v in x:
    s+=v+'_'
s=s[:-1]
print(s)

29.

x=input()

print(x+'同学,人生苦短,我学python')
print(x[0]+'大侠,学好python,走遍天下也不怕')
print(x[1:]+'小朋友,学好python,你最帅')

标签:num1,int,pta,else,lab,str,print,input
From: https://www.cnblogs.com/hongwei408/p/16934312.html

相关文章