-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.py
More file actions
57 lines (44 loc) · 1.2 KB
/
Copy pathmodule.py
File metadata and controls
57 lines (44 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 27 22:27:51 2021
@author: xuewu
"""
#!/usr/bin/env python3
""" module.py - an example of a Python module """
__counter = 0
def suml(the_list):
global __counter
__counter += 1
the_sum = 0
for element in the_list:
the_sum += element
return the_sum
def prodl(the_list):
global __counter
__counter += 1
prod = 1
for element in the_list:
prod *= element
return prod
if __name__ == "__main__":
print("I prefer to be a module, but I can do some tests for you.")
my_list = [i+1 for i in range(5)]
print(suml(my_list) == 15)
print(prodl(my_list) == 120)
# 1.4.1.14 How to use pip
import pygame
run = True
width = 400
height = 100
pygame.init()
screen = pygame.display.set_mode((width, height))
font = pygame.font.SysFont(None, 48)
text = font.render("Welcome to pygame", True, (255, 255, 255))
screen.blit(text, ((width - text.get_width()) // 2, (height - text.get_height()) // 2))
pygame.display.flip()
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT\
or event.type == pygame.MOUSEBUTTONUP\
or event.type == pygame.KEYUP:
run = False