Skip to content

Commit

Permalink
cool python apps
Browse files Browse the repository at this point in the history
  • Loading branch information
codebasics committed Jan 2, 2021
1 parent 7ce314e commit 0ae9690
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 1_language_translate/translator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# pip install googletrans==3.1.0a0

from googletrans import Translator
translator = Translator()

out = translator.translate("क्या हाल है", dest='en')
print(out)

mystory = '''Tell me who doesn't love baby yoda from mandolarian?
Baby yoda has shaken me like soda.
'''
out = translator.translate(mystory, dest='hi')
print(out.text)

out = translator.translate("I am learning python", dest='gu')
print(out)
30 changes: 30 additions & 0 deletions 2_bitcoin_mining/bitcoin_mining.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from hashlib import sha256
MAX_NONCE = 100000000000

def SHA256(text):
return sha256(text.encode("ascii")).hexdigest()

def mine(block_number, transactions, previous_hash, prefix_zeros):
prefix_str = '0'*prefix_zeros
for nonce in range(MAX_NONCE):
text = str(block_number) + transactions + previous_hash + str(nonce)
new_hash = SHA256(text)
if new_hash.startswith(prefix_str):
print(f"Yay! Successfully mined bitcoins with nonce value:{nonce}")
return new_hash

raise BaseException(f"Couldn't find correct has after trying {MAX_NONCE} times")

if __name__=='__main__':
transactions='''
Dhaval->Bhavin->20,
Mando->Cara->45
'''
difficulty=4 # try changing this to higher number and you will see it will take more time for mining as difficulty increases
import time
start = time.time()
print("start mining")
new_hash = mine(5,transactions,'0000000xa036944e29568d0cff17edbe038f81208fecf9a66be9a2b8321c6ec7', difficulty)
total_time = str((time.time() - start))
print(f"end mining. Mining took: {total_time} seconds")
print(new_hash)

1 comment on commit 0ae9690

@mikyR
Copy link

@mikyR mikyR commented on 0ae9690 Jul 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hola creo que es muy buena idea este proyecto gracias

Please sign in to comment.