2022.6.21 Python review course

Gold 250 2022-06-23 16:45:11 阅读数:616

2022.6.21pythonreviewcourse

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()
版权声明:本文为[Gold 250]所创,转载请带上原文链接,感谢。 https://pythonmana.com/2022/174/202206231600105177.html