├── Helloworld.py ├── sentimentanalysis.py ├── Pattern2 ├── leetcode-groupAnagrams.py ├── chiper_algorithm.py ├── kavach.py ├── README.md └── calculator_tkinter.py /Helloworld.py: -------------------------------------------------------------------------------- 1 | print("Hello world") 2 | -------------------------------------------------------------------------------- /sentimentanalysis.py: -------------------------------------------------------------------------------- 1 | import nltk 2 | from nltk.sentiment.vader import SentimentIntensityAnalyzer 3 | 4 | # Download VADER lexicon (if not already downloaded) 5 | nltk.download('vader_lexicon') 6 | sia = SentimentIntensityAnalyzer() 7 | def analyze_sentiment(text): 8 | sentiment_scores = sia.polarity_scores(text) 9 | compound_score = sentiment_scores['compound'] 10 | if compound_score >= 0.05: 11 | sentiment = "Positive" 12 | elif compound_score <= -0.05: 13 | sentiment = "Negative" 14 | else: 15 | sentiment = "Neutral" 16 | 17 | return sentiment, sentiment_scores 18 | 19 | sample_text = "I love this product! It's amazing." 20 | sentiment, scores = analyze_sentiment(sample_text) 21 | print("Sentiment:", sentiment) 22 | print("Sentiment Scores:", scores) 23 | -------------------------------------------------------------------------------- /Pattern2: -------------------------------------------------------------------------------- 1 | # Python 3.x code to demonstrate star pattern 2 | 3 | # Function to demonstrate printing pattern 4 | def pypart2(n): 5 | 6 | # number of spaces 7 | k = 2*n - 2 8 | 9 | # outer loop to handle number of rows 10 | for i in range(0, n): 11 | 12 | # inner loop to handle number spaces 13 | # values changing acc. to requirement 14 | for j in range(0, k): 15 | print(end=" ") 16 | 17 | # decrementing k after each loop 18 | k = k - 2 19 | 20 | # inner loop to handle number of columns 21 | # values changing acc. to outer loop 22 | for j in range(0, i+1): 23 | 24 | # printing stars 25 | print("* ", end="") 26 | 27 | # ending line after each row 28 | print("\r") 29 | 30 | # Driver Code 31 | n = 5 32 | pypart2(n) 33 | 34 | ''' 35 | * 36 | * * 37 | * * * 38 | * * * * 39 | * * * * * 40 | ''' 41 | -------------------------------------------------------------------------------- /leetcode-groupAnagrams.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def groupAnagrams(self, strs): 3 | """ 4 | :type strs: List[str] 5 | :rtype: List[List[str]] 6 | """ 7 | ans=[] 8 | dict1 = {} 9 | if strs==[""]: 10 | return [[""]] 11 | elif len(strs) == 1: 12 | return [strs] 13 | else : 14 | 15 | for word in strs: 16 | sorted_word = "".join(sorted(word)) 17 | if sorted_word not in dict1: 18 | dict1[sorted_word]=[word] 19 | else: 20 | dict1[sorted_word].append(word) 21 | 22 | for words in dict1.values(): 23 | ans.append(words) 24 | return ans 25 | 26 | dict1= {} 27 | for word in strs: 28 | sorted_word = "".join(sorted(word)) 29 | if sorted_word not in dict1: 30 | dict1[sorted_word]=[word] 31 | else: 32 | dict1[sorted_word].append(word) 33 | result = [] 34 | for words in dict1.values(): 35 | result.append(words) 36 | return result -------------------------------------------------------------------------------- /chiper_algorithm.py: -------------------------------------------------------------------------------- 1 | def caesar_cipher(message, shift, decrypt=False): 2 | result = "" 3 | 4 | # Adjust the shift value for decryption 5 | if decrypt: 6 | shift = -shift 7 | 8 | for char in message: 9 | if char.isalpha(): 10 | # Determine whether the character is uppercase or lowercase 11 | is_upper = char.isupper() 12 | 13 | # Shift the character 14 | shifted_char = chr((ord(char) + shift - ord('A' if is_upper else 'a')) % 26 + ord('A' if is_upper else 'a')) 15 | 16 | # Append the shifted character to the result 17 | result += shifted_char 18 | else: 19 | # If the character is not alphabetic, keep it unchanged 20 | result += char 21 | 22 | return result 23 | 24 | # Get input from the user 25 | message = input("Enter the message: ") 26 | shift = int(input("Enter the shift value: ")) 27 | 28 | # Encrypt the message using the Caesar cipher 29 | encrypted_message = caesar_cipher(message, shift) 30 | print("Encrypted message:", encrypted_message) 31 | 32 | # Decrypt the message using the Caesar cipher 33 | decrypted_message = caesar_cipher(encrypted_message, shift, decrypt=True) 34 | print("Decrypted message:", decrypted_message) 35 | -------------------------------------------------------------------------------- /kavach.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """Kavach.ipynb 3 | 4 | Automatically generated by Colaboratory. 5 | 6 | Original file is located at 7 | https://colab.research.google.com/drive/1Q0qFkoVp_HyzkThKZj6hLabFBW5XWpFu 8 | 9 | Keyword Extraction 10 | """ 11 | 12 | !pip install spacy 13 | 14 | import spacy 15 | from spacy.lang.en.stop_words import STOP_WORDS 16 | 17 | nlp = spacy.load('en_core_web_sm') 18 | 19 | input_string = input("Enter a string of around 25 words: ") 20 | doc = nlp(input_string) 21 | 22 | filtered_tokens = [token.text for token in doc if not token.is_stop and not token.is_punct] 23 | 24 | noun_chunks = list(doc.noun_chunks) 25 | keywords = [] 26 | for chunk in noun_chunks: 27 | if chunk.root.text in filtered_tokens: 28 | keywords.append(chunk.text) 29 | if len(keywords) == 5: 30 | break 31 | 32 | output_sentence = " ".join(keywords) 33 | print("Keywords: ", keywords) 34 | print("Output sentence: ", output_sentence) 35 | 36 | """Fake News Detection""" 37 | 38 | from sklearn.naive_bayes import MultinomialNB 39 | from sklearn.feature_extraction.text import TfidfVectorizer 40 | import numpy as np 41 | 42 | main_sentence = "Elon Musk is worried about Ai development" 43 | 44 | sentences = [ 45 | "Elon Musk and others urge AI pause, citing risks to society", 46 | "Elon Musk among experts urging a halt to AI training", 47 | "Elon Musk loves A.I", 48 | "Elon Musk's AI History May Be Behind His Call To Pause Development", 49 | "Elon Musk, who co-founded firm behind ChatGPT, warns A.I. is 'one of the biggest risks' to civilization", 50 | "Elon Musk and experts say AI development should be paused immediately MakeUseOf", 51 | "Artificial intelligence stresses me out, says Elon Musk", 52 | "Elon Musk joins hundreds calling for a six-month pause on AI development in an open letter", 53 | "Why Elon Musk fears artificial intelligence", 54 | "Musk, scientists call for halt to AI race sparked by ChatGPT" 55 | ] 56 | 57 | vectorizer = TfidfVectorizer(stop_words='english') 58 | X_main = vectorizer.fit_transform([main_sentence] + sentences) 59 | X_sentences = vectorizer.transform(sentences) 60 | X = np.vstack([X_main.toarray(), X_sentences.toarray()]) 61 | 62 | clf = MultinomialNB() 63 | clf.fit(X[:1], [1]) 64 | pred_labels = clf.predict(X[1:]) 65 | 66 | for i, sentence in enumerate(sentences): 67 | print(f"Sentence {i+1}: {sentence}") 68 | if pred_labels[i] == 0: 69 | print("Accuracy: 0.0%") 70 | print("Fake news") 71 | else: 72 | print(f"Accuracy: {clf.predict_proba(X[1:])[i][0]*100:.2f}%") 73 | print("Correct news") 74 | print() 75 | 76 | """Using pre trained BERT""" 77 | 78 | !pip install transformers 79 | 80 | from sklearn.linear_model import LogisticRegression 81 | from transformers import BertTokenizer, BertModel 82 | tokenizer = BertTokenizer.from_pretrained('bert-base-uncased') 83 | model = BertModel.from_pretrained('bert-base-uncased') 84 | 85 | !pip install torch 86 | 87 | import torch 88 | sentences_embeddings = [] 89 | for sentence in [main_sentence] + sentences: 90 | encoded_dict = tokenizer.encode_plus( 91 | sentence, 92 | add_special_tokens=True, 93 | max_length=64, 94 | padding='max_length', 95 | return_attention_mask=True, 96 | return_tensors='pt', 97 | ) 98 | with torch.no_grad(): 99 | outputs = model(encoded_dict['input_ids'], encoded_dict['attention_mask']) 100 | last_hidden_states = outputs[0] 101 | sentence_embedding = torch.mean(last_hidden_states, dim=1).squeeze().numpy() 102 | sentences_embeddings.append(sentence_embedding) 103 | 104 | cosine_similarities = [] 105 | for i in range(1, len(sentences_embeddings)): 106 | cosine_sim = np.dot(sentences_embeddings[0], sentences_embeddings[i]) / (np.linalg.norm(sentences_embeddings[0]) * np.linalg.norm(sentences_embeddings[i])) 107 | cosine_similarities.append(cosine_sim) 108 | 109 | import pandas as pd 110 | df = pd.DataFrame({'sentence': sentences, 'cosine_similarity': cosine_similarities}) 111 | tfidf_vectorizer = TfidfVectorizer(stop_words='english', max_features=1000) 112 | tfidf_features = tfidf_vectorizer.fit_transform(df['sentence']) 113 | 114 | X = np.hstack((tfidf_features.toarray(), df['cosine_similarity'].values.reshape(-1, 1))) 115 | y = np.array([0] * (len(sentences)-1) + [1]) 116 | clf = LogisticRegression(random_state=42, max_iter=1000).fit(X, y) 117 | 118 | # predict the labels for each sentence and print the results 119 | for i, sentence in enumerate(sentences): 120 | X_test = np.hstack((tfidf_vectorizer.transform([sentence]).toarray(), np.array([cosine_similarities[i-1]]).reshape(-1, 1))) 121 | y_pred = clf.predict(X_test)[0] 122 | if y_pred == 1: 123 | accuracy = clf.predict_proba(X_test)[0][1]*100 124 | print(f"Sentence: {sentence}") 125 | print(f"Accuracy: {accuracy:.2f}%") 126 | if accuracy >= 90: 127 | print("Correct news") 128 | else: 129 | print("Fake news") 130 | else: 131 | accuracy = clf.predict_proba(X_test)[0][0]*100 132 | print(f"Sentence: {sentence}") 133 | print(f"Accuracy: {accuracy:.2f}%") 134 | if accuracy >= 90: 135 | print("Correct news") 136 | else: 137 | print("Fake news") 138 | print() 139 | 140 | import matplotlib.pyplot as plt 141 | accuracies = [] 142 | for i, sentence in enumerate(sentences): 143 | X_test = np.hstack((tfidf_vectorizer.transform([sentence]).toarray(), np.array([cosine_similarities[i-1]]).reshape(-1, 1))) 144 | y_pred = clf.predict(X_test)[0] 145 | if y_pred == 1: 146 | accuracy = clf.predict_proba(X_test)[0][1]*100 147 | accuracies.append(accuracy) 148 | else: 149 | accuracy = clf.predict_proba(X_test)[0][0]*100 150 | accuracies.append(accuracy) 151 | 152 | plt.plot(accuracies) 153 | plt.xlabel("Sentence index") 154 | plt.ylabel("Accuracy (%)") 155 | plt.title("Accuracy of sentence classifications") 156 | plt.show() 157 | 158 | from sklearn.datasets import load_iris 159 | from sklearn.tree import DecisionTreeClassifier, export_graphviz 160 | import graphviz 161 | iris = load_iris() 162 | X = iris.data 163 | y = iris.target 164 | clf = DecisionTreeClassifier() 165 | clf.fit(X, y) 166 | dot_data = export_graphviz(clf, out_file=None, feature_names=iris.feature_names, class_names=iris.target_names, filled=True, rounded=True, special_characters=True) 167 | graph = graphviz.Source(dot_data) 168 | graph.render("iris_decision_tree") -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hacktoberfest2023 2 | 3 | ### This repository aims to help code beginners with their first successful pull request and open source contribution. :partying_face: 4 | 5 | :star: Feel free to use this project to make your first contribution to an open-source project on GitHub. Practice making your first pull request to a public repository before doing the real thing! 6 | 7 | :star: Make sure to grab some cool swags during Hacktoberfest by getting involved in the open-source community. 8 | 9 | ### This repository is open to all members of the GitHub community. Any member can contribute to this project! :grin: 10 | 11 | ## What is Hacktoberfest? :thinking: 12 | A month-long celebration from October 1st to October 31st presented by [Digital Ocean](https://hacktoberfest.digitalocean.com/) and [DEV Community](https://dev.to/) collaborated with [GitHub](https://github.com/blog/2433-celebrate-open-source-this-october-with-hacktoberfest) to get people involved in [Open Source](https://github.com/open-source). Create your very first pull request to any public repository on GitHub and contribute to the open-source developer community. 13 | 14 | [https://hacktoberfest.digitalocean.com/](https://hacktoberfest.digitalocean.com/) 15 | 16 | ## Rules :fire: 17 | To qualify for the __official limited edition Hacktoberfest shirt__, you must register [here](https://hacktoberfest.digitalocean.com/) and make four Pull Requests (PRs) between October 1-31, 2023 (in any time zone). PRs can be made to any public repository on GitHub, not only the ones with issues labeled Hacktoberfest. This year, the __first 40,000__ participants who complete the challenge will earn a T-shirt. 18 | 19 | ## Steps to follow :scroll: 20 | 21 | ### Tip : Complete this process in GitHub (in your browser) 22 | 23 | ```mermaid 24 | flowchart LR 25 | Fork[Fork the project]-->branch[Create a New Branch] 26 | branch-->Edit[Edit file] 27 | Edit-->commit[Commit the changes] 28 | commit -->|Finally|creatpr((Create a Pull Request)) 29 | 30 | ``` 31 | 32 | ### 0. Star The Repository :star2: 33 | 34 | Star the repository by pressing the topmost-right button to start your wonderful journey. 35 | 36 | ### 1. Fork it :fork_and_knife: 37 | 38 | You can get your own fork/copy of [HacktoberFest-2023](https://github.com/Open-Source-you/Hackotberfest2023 by using the Fork button. 39 | 40 | 41 | ### 2. Clone it :busts_in_silhouette: 42 | 43 | `NOTE: commands are to be executed on Linux, Mac, and Windows(using Powershell)` 44 | 45 | You need to clone or (download) it to local machine using 46 | 47 | ```sh 48 | $ git clone https://github.com/Open-Source-you/Hackotberfest2023.git 49 | ``` 50 | 51 | > This makes a local copy of the repository in your machine. 52 | Once you have cloned the `Hacktoberfest-2023` repository in Github, move to that folder first using change directory command on Linux, Mac, and Windows(PowerShell to be used). 53 | 54 | ```sh 55 | # This will change directory to a folder Hacktoberfest-2023 56 | $ cd Hackotberfest2023 57 | ``` 58 | 59 | Move to this folder for all other commands. 60 | 61 | ### 3. Set it up :arrow_up: 62 | 63 | Run the following commands to see that *your local copy* has a reference to *your forked remote repository* in Github :octocat: 64 | 65 | ```sh 66 | $ git remote -v 67 | origin https://github.com/Your_Username/Hacktoberfest-2023.git (fetch) 68 | origin https://github.com/Your_Username/Hacktoberfest-2023.git (push) 69 | ``` 70 | 71 | Now, let's add a reference to the original [Hacktoberfest-2023]https://github.com/Open-Source-you/Hackotberfest2023) repository using 72 | 73 | ```sh 74 | $ git remote add upstream https://github.com/Open-Source-you/Hackotberfest2023.git 75 | ``` 76 | 77 | > This adds a new remote named ***upstream***. 78 | See the changes using 79 | 80 | ```sh 81 | $ git remote -v 82 | origin https://github.com/Your_Username/Hacktoberfest-2023.git (fetch) 83 | origin https://github.com/Your_Username/Hacktoberfest-2023.git (push) 84 | upstream https://github.com/Remote_Username/Hacktoberfest-2023.git (fetch) 85 | upstream https://github.com/Remote_Username/Hacktoberfest-2023.git (push) 86 | ``` 87 | `In your case, you will see` 88 | ```sh 89 | $ git remote -V 90 | origin https://github.com/Your_Username/Hacktoberfest-2023.git (fetch) 91 | origin https://github.com/Your_Username/Hacktoberfest-2023.git (push) 92 | upstream https://github.com/kishanrajput23/Hacktoberfest-2023.git (fetch) 93 | upstream https://github.com/kishanrajput23/Hacktoberfest-2023.git (push) 94 | ``` 95 | 96 | ### 4. Sync it :recycle: 97 | 98 | Always keep your local copy of the repository updated with the original repository. 99 | Before making any changes and/or in an appropriate interval, run the following commands *carefully* to update your local repository. 100 | 101 | ```sh 102 | # Fetch all remote repositories and delete any deleted remote branches 103 | $ git fetch --all --prune 104 | # Switch to `main` branch 105 | $ git checkout main 106 | # Reset local `main` branch to match the `upstream` repository's `main` branch 107 | $ git reset --hard upstream/main 108 | # Push changes to your forked `Hacktoberfest-2021` repo 109 | $ git push origin main 110 | ``` 111 | 112 | ### 5. Ready Steady Go... :turtle: :rabbit2: 113 | 114 | Once you have completed these steps, you are ready to start contributing by checking our `Good First Issue` Issues and creating [pull requests](https://github.com/kishanrajput23/Hacktoberfest-2023/pulls). 115 | 116 | ### 6. Create a new branch :bangbang: 117 | 118 | Whenever you are going to contribute. Please create a separate branch using command and keep your `main` branch clean (i.e. synced with remote branch). 119 | 120 | ```sh 121 | # It will create a new branch with name Branch_Name and switch to branch Folder_Name 122 | $ git checkout -b BranchName 123 | ``` 124 | 125 | Create a separate branch for contribution and try to use the same name of the branch as of folder. 126 | 127 | To switch to the desired branch 128 | 129 | ```sh 130 | # To switch from one folder to other 131 | $ git checkout BranchName 132 | ``` 133 | 134 | To add the changes to the branch. Use 135 | 136 | ```sh 137 | # To add all files to branch Folder_Name 138 | $ git add . 139 | ``` 140 | 141 | Type in a message relevant for the code reviewer using 142 | 143 | ```sh 144 | # This message get associated with all files you have changed 145 | $ git commit -m 'relevant message' 146 | ``` 147 | 148 | Now, Push your awesome work to your remote repository using 149 | 150 | ```sh 151 | # To push your work to your remote repository 152 | $ git push -u origin BranchName 153 | ``` 154 | 155 | Finally, go to your repository in the browser and click on `compare and pull requests`. 156 | Then add a title and description to your pull request that explains your precious effort. 157 | 158 | 159 | 160 | 161 | ## Help Contributing Guides :crown: 162 | 163 | We love to have `articles` and `codes` in different languages and the `betterment` of existing ones. 164 | 165 | Please discuss it with us first by creating a new issue. 166 | -------------------------------------------------------------------------------- /calculator_tkinter.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | import math 3 | 4 | root = Tk() 5 | root.title("Calculator GUI By Aatif") 6 | 7 | e1 = Entry(root,bg = "#9de5f2",width = 33,font = ("calibri",11)) 8 | e2 = Entry(root,bg = "#9df2c8",width = 11,font = ("calibri",11)) 9 | 10 | e1.grid(row = 0,column = 0,columnspan = 3) 11 | e2.grid(row = 0,column = 3,columnspan = 1) 12 | 13 | def button_click(number): 14 | if(number == 10): 15 | e1.insert(END,'.') 16 | else: 17 | e1.insert(END,number) 18 | 19 | def button_clear(): 20 | e1.delete(0,END) 21 | 22 | def button_add(): 23 | e2.delete(0,END) 24 | e2.insert(0,'+') 25 | first_number = e1.get() 26 | global f_num 27 | f_num = float(first_number) 28 | global oper 29 | oper = "addition" 30 | e1.delete(0,END) 31 | 32 | def button_sub(): 33 | e2.delete(0,END) 34 | e2.insert(0,'-') 35 | first_number = e1.get() 36 | global f_num 37 | f_num = float(first_number) 38 | global oper 39 | oper = "subtraction" 40 | e1.delete(0,END) 41 | 42 | def button_mul(): 43 | e2.delete(0,END) 44 | e2.insert(0,'*') 45 | first_number = e1.get() 46 | global f_num 47 | f_num = float(first_number) 48 | global oper 49 | oper = "multiplication" 50 | e1.delete(0,END) 51 | 52 | def button_div(): 53 | e2.delete(0,END) 54 | e2.insert(0,'/') 55 | first_number = e1.get() 56 | global f_num 57 | f_num = float(first_number) 58 | global oper 59 | oper = "division" 60 | e1.delete(0,END) 61 | 62 | def button_perc(): 63 | e2.delete(0,END) 64 | e2.insert(0,'%') 65 | first_number = e1.get() 66 | global f_num 67 | f_num = float(first_number) 68 | global oper 69 | oper = "percentage" 70 | e1.delete(0,END) 71 | 72 | def button_power(): 73 | e2.delete(0,END) 74 | e2.insert(0,'^') 75 | first_number = e1.get() 76 | global f_num 77 | f_num = float(first_number) 78 | global oper 79 | oper = "power" 80 | e1.delete(0,END) 81 | 82 | def button_gcd(): 83 | e2.delete(0,END) 84 | e2.insert(0,"gcd") 85 | first_number = e1.get() 86 | global f_num 87 | f_num = int(first_number) 88 | global oper 89 | oper = "gcd" 90 | e1.delete(0,END) 91 | 92 | def button_log_e(): 93 | e2.delete(0,END) 94 | e2.insert(0,'ln') 95 | first_number = e1.get() 96 | global f_num 97 | f_num = float(first_number) 98 | global oper 99 | oper = "natural_logarithm" 100 | e1.delete(0,END) 101 | 102 | def button_log_10(): 103 | e2.delete(0,END) 104 | e2.insert(0,'log_10') 105 | first_number = e1.get() 106 | global f_num 107 | f_num = float(first_number) 108 | global oper 109 | oper = "common_logarithm" 110 | e1.delete(0,END) 111 | 112 | def button_sin(): 113 | e2.delete(0,END) 114 | e2.insert(0,"sin") 115 | first_number = e1.get() 116 | global f_num 117 | f_num = float(first_number) 118 | global oper 119 | oper = "sine" 120 | e1.delete(0,END) 121 | 122 | def button_cos(): 123 | e2.delete(0,END) 124 | e2.insert(0,"cos") 125 | first_number = e1.get() 126 | global f_num 127 | f_num = float(first_number) 128 | global oper 129 | oper = "cosine" 130 | e1.delete(0,END) 131 | 132 | def button_tan(): 133 | e2.delete(0,END) 134 | e2.insert(0,"tan") 135 | first_number = e1.get() 136 | global f_num 137 | f_num = float(first_number) 138 | global oper 139 | oper = "tangent" 140 | e1.delete(0,END) 141 | 142 | def button_fact(): 143 | e2.delete(0,END) 144 | e2.insert(0,"fact") 145 | first_number = e1.get() 146 | global f_num 147 | f_num = int(first_number) 148 | global oper 149 | oper = "factorial" 150 | e1.delete(0,END) 151 | 152 | def button_abs(): 153 | e2.delete(0,END) 154 | e2.insert(0,"abs") 155 | first_number = e1.get() 156 | global f_num 157 | f_num = float(first_number) 158 | global oper 159 | oper = "absolute_val" 160 | e1.delete(0,END) 161 | 162 | def button_sqrt(): 163 | e2.delete(0,END) 164 | e2.insert(0,"sqrt") 165 | first_number = e1.get() 166 | global f_num 167 | f_num = float(first_number) 168 | global oper 169 | oper = "square_root" 170 | e1.delete(0,END) 171 | 172 | def button_inv(): 173 | e2.delete(0,END) 174 | e2.insert(0,"1/x") 175 | first_number = e1.get() 176 | global f_num 177 | f_num = float(first_number) 178 | global oper 179 | oper = "inverse" 180 | e1.delete(0,END) 181 | 182 | def button_equal(): 183 | if(oper == "natural_logarithm"): 184 | e1.delete(0,END) 185 | e1.insert(0,math.log(f_num)) 186 | elif(oper == "sine"): 187 | e1.delete(0,END) 188 | e1.insert(0,math.sin(f_num)) 189 | elif(oper == "cosine"): 190 | e1.delete(0,END) 191 | e1.insert(0,math.cos(f_num)) 192 | elif(oper == "tangent"): 193 | e1.delete(0,END) 194 | e1.insert(0,math.tan(f_num)) 195 | elif(oper == "tangent"): 196 | e1.delete(0,END) 197 | e1.insert(0,math.log10(f_num)) 198 | elif(oper == "factorial"): 199 | e1.delete(0,END) 200 | e1.insert(0,math.factorial(f_num)) 201 | elif(oper == "absolute_val"): 202 | e1.delete(0,END) 203 | e1.insert(0,abs(f_num)) 204 | elif(oper == "square_root"): 205 | e1.delete(0,END) 206 | e1.insert(0,math.sqrt(f_num)) 207 | elif(oper == "inverse"): 208 | e1.delete(0,END) 209 | e1.insert(0,(1 / f_num)) 210 | 211 | else: 212 | second_number = float(e1.get()) 213 | e1.delete(0,END) 214 | if oper == "addition" : 215 | e1.insert(0, f_num + second_number) 216 | elif oper == "subtraction" : 217 | e1.insert(0,f_num - second_number) 218 | elif oper == "multiplication" : 219 | e1.insert(0,f_num * second_number) 220 | elif oper == "division" : 221 | e1.insert(0,f_num / second_number) 222 | elif oper == "percentage" : 223 | e1.insert(0, (f_num / second_number) * 100) 224 | elif oper == "power" : 225 | e1.insert(0,pow(f_num,second_number)) 226 | # elif oper == "gcd" : 227 | # second_number = int(second_number) 228 | # res = math.gcd(f_num,second_number) 229 | # e1.insert(0,res) 230 | 231 | button_1 = Button(root,text = "7",width = 10,height = 5,bg = "#e89b72",command = lambda : button_click(7))#7 232 | button_2 = Button(root,text = "8",width = 10,height = 5,bg = "#e89b72",command = lambda : button_click(8))#8 233 | button_3 = Button(root,text = "9",width = 10,height = 5,bg = "#e89b72",command = lambda : button_click(9))#9 234 | button_4 = Button(root,text = "sin",width = 10,height = 5,bg = "#e8c37d",command = button_sin)#sin 235 | button_5 = Button(root,text = "4",width = 10,height = 5,bg = "#e89b72",command = lambda : button_click(4))#4 236 | button_6 = Button(root,text = "5",width = 10,height = 5,bg = "#e89b72",command = lambda : button_click(5))#5 237 | button_7 = Button(root,text = "6",width = 10,height = 5,bg = "#e89b72",command = lambda : button_click(6))#6 238 | button_8 = Button(root,text = "cos",width = 10,height = 5,bg = "#e8c37d",command = button_cos)#cos 239 | button_9 = Button(root,text = "1",width = 10,height = 5,bg = "#e89b72",command = lambda: button_click(1))#1 240 | button_10 = Button(root,text = "2",width = 10,height = 5,bg = "#e89b72",command = lambda : button_click(2))#2 241 | button_11 = Button(root,text = "3",width = 10,height = 5,bg = "#e89b72",command = lambda: button_click(3))#3 242 | button_12= Button(root,text = "tan",width = 10,height = 5,bg = "#e8c37d",command = button_tan)#tan 243 | button_13= Button(root,text = "0",width = 10,height = 5,bg = "#e89b72",command = lambda : button_click(0))#0 244 | button_14= Button(root,text = "+",width = 10,height = 5,bg = "#e8c37d",command = button_add)#+ 245 | button_15= Button(root,text = "-",width = 10,height = 5,bg = "#e8c37d",command = button_sub)#- 246 | button_16= Button(root,text = "fact",width = 10,height = 5,bg = "#e8c37d",command = button_fact)#fact 247 | button_17= Button(root,text = "*",width = 10,height = 5,bg = "#e8c37d",command = button_mul)#* 248 | button_18= Button(root,text = "/",width = 10,height = 5,bg = "#e8c37d",command = button_div)#/ 249 | button_19= Button(root,text = "abs",width = 10,height = 5,bg = "#e8c37d",command = button_abs)#abs 250 | button_20= Button(root,text = "log10",width = 10,height = 5,bg = "#e8c37d",command = button_log_10)#log10 251 | button_21= Button(root,text = "sqrt",width = 10,height = 5,bg = "#e8c37d",command = button_sqrt)#sqrt 252 | button_22= Button(root,text = "%",width = 10,height = 5,bg = "#e8c37d",command = button_perc)#% 253 | button_23= Button(root,text = "pow",width = 10,height = 5,bg = "#e8c37d",command = button_power)#pow 254 | button_24= Button(root,text = "ln",width = 10,height = 5,bg = "#e8c37d",command = button_log_e)#ln 255 | button_25= Button(root,text = "=",width = 10,height = 5,bg = "#9de5f2",command = button_equal)#= 256 | button_26= Button(root,text = "1/x",width = 10,height = 5,bg = "#e8c37d",command = button_inv)#1/x 257 | button_27 = Button(root,text = ".",width = 10,height = 5,bg = "#e8c37d",command =lambda : button_click(10))#gcd 258 | button_28 = Button(root,text = "Clear",width = 10,height = 5,bg = "#9df2c8",command = button_clear)#clear 259 | 260 | button_1.grid(row = 1,column = 0) 261 | button_2.grid(row = 1,column = 1) 262 | button_3.grid(row = 1,column = 2) 263 | button_4.grid(row = 1,column = 3) 264 | button_5.grid(row = 2,column = 0) 265 | button_6.grid(row = 2,column = 1) 266 | button_7.grid(row = 2,column = 2) 267 | button_8.grid(row = 2,column = 3) 268 | button_9.grid(row = 3,column = 0) 269 | button_10.grid(row = 3,column = 1) 270 | button_11.grid(row = 3,column = 2) 271 | button_12.grid(row = 3,column = 3) 272 | button_13.grid(row = 4,column = 0) 273 | button_14.grid(row = 4,column = 1) 274 | button_15.grid(row = 4,column = 2) 275 | button_16.grid(row = 4,column = 3) 276 | button_17.grid(row = 5,column = 0) 277 | button_18.grid(row = 5,column = 1) 278 | button_19.grid(row = 5,column = 2) 279 | button_20.grid(row = 5,column = 3) 280 | button_21.grid(row = 6,column = 0) 281 | button_22.grid(row = 6,column = 1) 282 | button_23.grid(row = 6,column = 2) 283 | button_24.grid(row = 6,column = 3) 284 | button_25.grid(row = 7,column = 0) 285 | button_26.grid(row = 7,column = 1) 286 | button_27.grid(row = 7,column = 2) 287 | button_28.grid(row = 7,column = 3) 288 | 289 | root.mainloop() --------------------------------------------------------------------------------