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 hashlib | |
| def create_file_hash(filename, algorithm='sha256'): | |
| """Creates a hash (message digest) of a given file.""" | |
| try: | |
| hash_func = getattr(hashlib, algorithm)() # Choose hash algorithm | |
| with open(filename, 'rb') as file: | |
| while chunk := file.read(4096): # Read in chunks | |
| hash_func.update(chunk) |
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
| TASK 12 A | |
| # importing libraries | |
| import pygame | |
| import time | |
| import random | |
| snake_speed = 15 | |
| # Window size |
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
| TASK 11A | |
| import tkinter as tk | |
| # Function to change font style | |
| def change_font(): | |
| label.config(font=("Arial", 18, "bold")) | |
| # Create main window |
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
| TASK 10A | |
| #pip install matplotlib | |
| import matplotlib.pyplot as plt | |
| languages = ['Java', 'Python', 'PHP', 'JavaScript', 'C#', 'C++'] | |
| popularity = [22.2, 17.6, 8.8, 8, 7.7, 6.7] | |
| plt.bar(languages, popularity, color='b') | |
| plt.title('Popularity of Programming Languages') |
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
| TASK 9A | |
| # Initialize the list of grades | |
| grades = [85, 90, 78, 92, 88] | |
| # Display the grades list | |
| print("Grades List:", grades) | |
| # Prompt the user to enter the index of the grade they want to view | |
| try: |
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
| 674882 |
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
| TASK 8A | |
| def number_sequence(start, end, step=1): | |
| current = start | |
| while current <= end: | |
| yield current | |
| current += step | |
| start = int(input("Enter the starting number: ")) | |
| end = int(input("Enter the ending number: ")) | |
| step = int(input("Enter the step value: ")) |
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
| TASK 6A | |
| def copy_files(file_paths): | |
| for file_path in file_paths: | |
| if os.path.exists(file_path): | |
| with open(file_path, 'r') as original_file: | |
| original_content = original_file.read() | |
| copy_file_path = file_path.split('.')[0] + '_copy.' + file_path.split('.')[1] | |
| with open(copy_file_path, 'w') as copy_file: | |
| copy_file.write(original_content) |
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
| TASK 5A | |
| def find_employee_by_id(employees, target_id): | |
| for employee in employees: | |
| if employee['id'] == target_id: | |
| return employee | |
| return None | |
| # Test the function | |
| employees = [ |
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
| TASK 3A | |
| # Function to find k'th non repeating character | |
| # in string | |
| from collections import OrderedDict | |
| def kthRepeating(input,k): | |
| # OrderedDict returns a dictionary data structure having characters of input | |
| # string as keys in the same order they were inserted and 0 as their default value | |
| dict=OrderedDict.fromkeys(input,0) |
NewerOlder