Input abcd, Output ab-cd
# Loop input
a,b,c,d = (int(input()) for i in range(4))
print("DIFERENCA =",a*b-c*d)
Input ab, Determine whether there is a multiple relationship
# split Input
a, b = map(int, input().split()) # split Press space and \n Split string , map turn int
if b % a == 0 or a % b == 0:
print("Sao Multiplos")
else:
print("Nao sao Multiplos")
Give a json data , Find and output the value of a leaf node
# Dictionary nesting
t1={
"carnivoro":"aguia","onivoro":"pomba"}
t2={
"onivoro":"homem","herbivoro":"vaca"}
t3={
"hematofago":"pulga","herbivoro":"lagarta"}
t4={
"hematofago":"sanguessuga","onivoro":"minhoca"}
r1={
"ave":t1,"mamifero":t2}
r2={
"inseto":t3,"anelideo":t4}
s={
"vertebrado":r1,"invertebrado":r2}
a,b,c=input(),input(),input() # input Read in one line at a time
print(s[a][b][c])
give 5 A price list of snacks .
Ask for a snack x The number of y When you need money .
# list Input
xy=list(map(int,input().split())) # map Return iterator ,list Turn to list
print(f'Total: R$ {
(4.00,4.50,5.00,2.00,1.50)[xy[0]-1]*xy[1]:.2f}')
Give a line of string with spaces , Find the length
print(len(input()))
For the input integer n, Output 1,2,3,n Sequence
n=0 End the program at
n = int(input())
while n:
for i in range (n):
print(i+1, end = " ")
print()
n = int(input())
Input n Number , Judge whether it is a prime number
import math
n = int(input())
for i in range(n):
x = int(input())
s = math.floor(math.sqrt(x))
p = True
for j in range(2, s+1):
if x%j==0 :
p = False
break
if p:
print(x, "is prime")
else:
print(x, "is not prime")
Give a 12*12 Matrix , Find the average value of the upper right part and the sum of the elements
op = input()
a = []
for i in range(12):
a.append(list(map(float, input().split())))
res = 0
for i in range(12):
for j in range(i+1, 12):
res += a[i][j]
if(op=='M'): res/=66
print("%.1f"%(res))
give n and m, take 1-nm The number of is filled into the matrix in the form of a back word snake
nm = input().split()
n = int(nm[0])
m = int(nm[1])
dx = [0,1,0,-1] # Go clockwise
dy = [1,0,-1,0]
res = [[0]*m for _ in range(n)] # Initialize array
x,y,a,b,d = 0,0,0,0,0
for k in range(1,n*m+1):
res[x][y] = k
a=x+dx[d] # One step at a time
b=y+dy[d]
if a<0 or a>=n or b<0 or b>=m or res[a][b]!=0: # Judge legally
d=(d+1)%4
a=x+dx[d]
b=y+dy[d]
x = a
y = b
for i in range(n):
for j in range(m):
print(f"{
res[i][j]} ", end="")
print()
give n, seek 1-n The whole arrangement
def dfs(cur):
if cur > n:
for i in range(1,n+1):
print(a[i], end=" ")
print()
else :
for i in range(1,n+1):
if(vis[i] == False):
vis[i] = True
a[cur] = i
dfs(cur+1)
vis[i] = False
n = int(input()) # Input
a = [0]*(n+1) # Declaration array
vis = [False]*(n+1)
dfs(1)