This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| roll_again = "yes" | |
| while roll_again == "yes": | |
| # Generates a random number | |
| # between 1 and 6 (including | |
| # both 1 and 6) | |
| dice_value = random.randint(1, 6) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = 5 | |
| b = 6 | |
| c = 7 | |
| s = (a + b + c) / 2 | |
| print("Value of s -->", s) | |
| area = (s * (s-a) * (s-b) * (s-c)) ** 0.5 | |
| print("Area of triangle -->", area) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| file_path = "data.csv" | |
| delimiter = "," | |
| required_fields = ["name", "emp_id"] | |
| df = pd.read_csv(file_path, sep=delimiter, usecols=required_fields) | |
| data_list = df.to_dict('records') | |
| print("Record Count --->", len(data_list)) | |
| print(data_list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def divide_chunks(l, n): | |
| """ | |
| Function to split a larger list into a set of smaller lists | |
| :param l: list | |
| :param n: number of splits | |
| :return: list of smaller lists | |
| """ | |
| # looping till length l | |
| for i in range(0, len(l), n): | |
| yield l[i:i + n] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import RPi.GPIO as GPIO | |
| from time import sleep | |
| GPIO.setwarnings(False) | |
| GPIO.setmode(GPIO.BOARD) | |
| GPIO.setup(8,GPIO.OUT, initial=GPIO.LOW) | |
| GPIO.setup(10,GPIO.OUT, initial=GPIO.LOW) | |
| while True: | |
| GPIO.output(8,GPIO.HIGH) #Turn on GPIO pin 8 – changing LOW to HIGH | |
| GPIO.output(10,GPIO.LOW) #Turn off GPIO pin 10 – changing HIGH to LOW |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Unit] | |
| Description=My Python Application | |
| After=network.target | |
| [Service] | |
| Type=simple | |
| # Another Type option: forking | |
| User=amal | |
| WorkingDirectory=/home/amal | |
| ExecStart=gunicorn app:app --bind 0.0.0.0:8080 --workers 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Flask | |
| app = Flask(__name__) | |
| @app.route("/") | |
| def hello(): | |
| return "Hello World!. This is Systemd Example" | |
| if __name__ == "__main__": | |
| app.run(host='0.0.0.0', port=8080) |