Commit 2da146fd by BellCodeEditor

auto save

parent c6188a1e
Showing with 44 additions and 6 deletions
import pygame '''
创建一个函数,可以接受一个字符串,然后返回该字符串的第一个和最后一个字符。return
'''
def new(a):
b = a[0]
c = a[-1]
return b,c
# 初始化pygame,为使用pygame做准备 b,c = new("python")
pygame.init() print(b,c)
# 创建一个窗口
??
\ No newline at end of file '''
编程实现:求解1-1000以内所有能被9整除的数字。
'''
方法一
for i in range(1,1001):
if i%9 == 0:
print(i)
方法二
for i in range(9,1000,9):
print(i)
'''
编程实现:求列表list=[4,2,54,99,10,23]的和
'''
list=[4,2,54,99,10,23]
sum = 0 # 累加器
for i in list:
sum = sum + i
print("和是:",sum)
'''
求列表中所有奇数的和
'''
list=[4,2,54,99,10,23,231,443,1213,5432,43]
sum = 0 # 累加器
for i in list:
if i%2 == 1:
sum = sum + i
print("奇数和是:",sum)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment