前缀表达式
list1 = list(input().split())
m = list1[0]
a = list1[1]
b = int(list1[2])
def jia():
return a + b
def jian():
return a - b
def cheng():
return a * b
def chu():
return a // b
if a and b <= 10:
if m == '+':
print(jia())
elif m == '-':
print(jian())
elif m == '*':
print(cheng())
elif m == '/':
print(chu())
Anagrams问题
s1 = input()
s2 = input()
if len(s1) != len(s2):
print("N")
exit()
s1 = set(s1.lower()) #把所有的字符转换为小写
s2 = set(s2.lower()) #set()是一个无序不重复元素集,基本功能包括
测试和消除重复元素
l1 = list(s1) #把这两个串放在一个列表里面
l2 = list(s2)
l = l1 + l2
if len(set(l)) == len(l1+l2)/2:
print('Y')
else:
print('N')
字母图形
while True:
try:
en = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n,m = map(int,input().split(" "))
for i in range(0,n):
if i == 0:
print(en[0:m])
else:
s = en[i:0:-1] + en
print(s[0:m])
except:
break
区间K大数查询
n = input()
s = list(map(int,input().split())) #放在列表里
m = int(input())
for i in range(0,m):
l,r,K = map(int,input().split())
list = s[l-1:r]
list.sort(reverse=True)
print(list[K-1])
圆的面积
import math #引入π
r = int(input())
s = math.pi * r * r
print("{:.7f}".format(s))#保留小数
寻找数组中的最大值
a = int(input())
array = list(map(int,input().split())) #放在列表里
print(max(array),array.index(max(array)))
|