Python Beginner Projects #1

Beginner Projects, that we’ll cover in this story:
- Shutdown Mac with Python
- Random Password Generator with Python
- Wall Clock Design with Python
- QR-Code Generator with Python
Shutdown Mac with Python
import os
os.system("shutdown /s /t 1")
Import os gives us the opportunity to communicate with the os or the operating system. We tell the system to shutdown with these two lines of code
Random Password Generator with Python
import randomlower = "abcdefghijklmnopqrstuvwxyz"
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
numbers = "0123456789"
symbols = "[]{}()*;/,_-"all = lower + upper + numbers + symbols
length = 16
password = "".join(random.sample(all,length))
print(password)
To generate a random password we mainly use the string concatenation function of python. We give the variables all the possible values they can hold and randomly pick one or two character from each variable. Then, we concatenate them.
Wall Clock Design with Python
import turtleimport randomclass analog:def __init__(self):self.color1 = random.random(), random.random(), random.random()self.color2 = random.random(), random.random(), random.random()turtle.screensize(canvwidth=600, canvheight=600)turtle.speed(10)turtle.ht()turtle.pensize(2)turtle.up()turtle.goto(-300, -300)turtle.color("blue")turtle.down()for _ in range(4):turtle.fd(600)turtle.lt(90)turtle.updef clockhand(self):turtle.goto(0, 0)turtle.lt(60)turtle.down()for i in range(1, 13):turtle.pensize(3)turtle.color("black")turtle.fd(250)turtle.write(i, font=("verdana", 15, "normal"))turtle.goto(0, 0)turtle.rt(30)def arrow(self):turtle.rt(90)turtle.begin_fill()for i in range(3):turtle.forward(8)turtle.left(120)turtle.forward(8)turtle.lt(90)turtle.end_fillif __name__ == "__main__":turtle.clearscreen()clock = analog()hour = 24hour = hour * 100minute = 1440clock.clockhand()from time import sleepsleep(90)
QR-Code Generator with Python
import pyqrcodeimport pngfrom pyqrcode import QRCodeQRstring = "https://www.instagram.com/p/CIPXGuTAXRD/"url = pyqrcode.create(QRstring)url.png('Desktop\\qr.png', scale = 8)
The first four projects of the beginner python edition.
Thanks for reading ;))))