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

2022.6.21 Python review course

編輯:Python

Several functions mentioned

  1. strip
    Remove the specified character or character sequence at the beginning and end of the string

  2. type
    The data type of the output variable

  3. count
    Statistics specify the starting point or the ending point , The number of occurrences of a character or substring

  4. insert
    Inserts the specified object into the list at the specified location

  5. sep
    Custom delimiter , Commonly used in print Function

Programming questions

  1. Read in sequence 4 Students' grades and average
score = []
avg = []
for i in range(0, 4):
score.append([0] * 3)
for i in range(0, 4):
for j in range(0, 3):
score[i][j] = int(input())
avg[i] += score[i][j]
for i in range(0, 4):
print(avg[i])
  1. Judge leap year or normal year
year = int(input("Please input a year"))
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
print(year,' It's a leap year ')
else:
print(year,' It's the year of the year ')
  1. Write a function , Exchange the values of two variables
def swap(a, b):
t = a
a = b
b = t
print(a, b)
  1. Print number of daffodils
for x in range(1, 10):
for y in range(0, 10):
for z in range(0, 10):
s1 = x * 100 + y * 10 + z
s2 = x**3 + y**3 + z**3
if s1 == s2:
print(s1)
  1. Create a text file , And write string , Then save it
file = open('C:/a.txt','w+')
a = "123456"
file.write(a)
file.close()

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