Monday, March 23, 2020

first pygame in python

import pygame, sys
from pygame.locals import *
pygame.init()
displaysurf=pygame.display.set_mode((400,300))
pygame.display.set_caption('Hello world!!')
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
           
    pygame.display.update()

output:

even or odd using python language

list_of_numbers=[1,2,3,4,5,6]
for number in list_of_numbers:
    if number%2==0:
        print(number,"is even")
    else :
        print(number,"is odd")

print("end of the code")

output:
1 is odd
2 is even
3 is odd
4 is even
5 is odd
6 is even
end of the code

tuple in python

n=input("enter a comma separated number:")
l=n.split(",")
t=tuple(l)
print("l=",l,"t=",t)
print(type(l),"\n",type(t))

output:
enter a comma separated number:2,3,4,5
l= ['2', '3', '4', '5'] t= ('2', '3', '4', '5')
<class 'list'>
 <class 'tuple'>

dictionary in python

n=int(input("enter a number:"))
d=dict()
for i in range(1,n+1):
    #print("i=",i)
    d[i]=i*i
print(d)


output:

enter a number:5
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}


python class topic video