Skip to main content

Posts

Showing posts from November, 2021

Snake game using python

  CODE: import math import random import pygame import random import tkinter as tk from tkinter import messagebox width = 500 height = 500 cols = 25 rows = 20 class cube():     rows = 20     w = 500     def __init__(self, start, dirnx=1, dirny=0, color=(255,0,0)):         self.pos = start         self.dirnx = dirnx         self.dirny = dirny # "L", "R", "U", "D"         self.color = color     def move(self, dirnx, dirny):         self.dirnx = dirnx         self.dirny = dirny         self.pos  = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny)                  def draw(self, surface, eyes=False):         dis = self.w // self.rows         i = self.pos[0]         j = self.pos[1]                  pygame.draw.rect(surface, self.color, (i*dis+1,j*dis+1,dis-2,dis-2))         if eyes:             centre = dis//2             radius = 3             circleMiddle = (i*dis+centre-radius,j*dis+8)             circleMiddle2 = (i*dis + dis -radius*2, j*dis+8)

Make clock using python

  CODE: import sys  from tkinter import* import time #for importing sys, tkinter, time #open cmd in pc and type pip install sys def tick(): time_string=time.strftime("%H:%M:%S") clock.config(text=time_string) clock.after(200,tick) root=Tk() clock=Label(root, font=("times", 35,"bold"), bg="pink") #you can change font size and color clock.grid(row=0, column=1) tick() root.mainloop() OUTPUT:

Make Rainbow using python

  Code: i mport turtle colors=['red','purple','blue','green','yellow','orange'] t=turtle.Pen() t.speed(0) turtle.bgcolor('black') for x in range(360): t.pencolor(colors[x%6]) t.width(x/100+1) t.forward(x) t.left(59) OUTPUT:

Make Age Calculator by using python

Code : print("Hello, what is your name ?") n1=input() print("Nice Name",n1)  print ("If you find you age then type your Date of birth in year") n2=input() print("type current year") n3=input() print("your age is",int(n3)-int(n2)) OUTPUT: