程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Introduction to python3 Grammar & acwing Django framework course

編輯:Python

Python3 Introduction to grammar & AcWing Django Framework course

List of articles

    • Python3 Introduction to grammar & AcWing Django Framework course
        • AcWing 608. Bad
        • AcWing 665. Multiple
        • AcWing 670. animal
        • AcWing 660. snacks
        • AcWing 760. String length
        • AcWing 721. Increasing sequence
        • AcWing 726. Prime number
        • AcWing 745. The upper right half of the array
        • AcWing 756. Snake matrix
        • AcWing 823. array

AcWing 608. Bad

Input abcd, Output ab-cd

# Loop input 
a,b,c,d = (int(input()) for i in range(4))
print("DIFERENCA =",a*b-c*d)

AcWing 665. Multiple

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")

AcWing 670. animal

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])

AcWing 660. snacks

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}')

AcWing 760. String length

Give a line of string with spaces , Find the length

print(len(input()))

AcWing 721. Increasing sequence

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())

AcWing 726. Prime number

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")

AcWing 745. The upper right half of the array

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))

AcWing 756. Snake matrix

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()

AcWing 823. array

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)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved