Python Codes Set 2
1. Snke Water Gun Game !
#Snake water gun game by Tanush Chauhan
import random
print("Welcome to Game")
print("\nRules\nThe computer's choice would be random\nYou have to enter your choice.\nThere will be 10 rounds.\nIf you win in more rounds than computer then you wil win else computer will win.\nBest of luck :).")
lst = [ "Snake" , "Water" , "Gun"]
i = 0
r = 1
c = 0
p = 0
while (i < 10):
a = random.choice(lst)
i = i+1
print("\n\nRound",r)
r = r+1
print("Please Enter You Choice Snake(s), Gun(g) or Water (w)")
q = input()
if q == "s":
if a == "Snake":
print("Draw. The Computers choice was" ,a)
a = random.choice(lst)
if i >9:
print("\n\nYour Win(s) =" , p)
print("Comuter's Win(s) =" , c)
if p>c:
print("Overall Winner : Player(You)")
elif p < c:
print("Overall Winner : Computer")
elif p == c:
print("Overall Winner : The Game has Draw")
else:
True
print("Do You Want to play again ? Yes(1) , No(2) :")
z = input()
if z == "1":
i = 0
r = 1
p = 0
c = 0
continue
elif z == "2":
break
else:
print("You entered a wrong Charecter Game ending...")
break
else:
continue
elif a == "Water":
print("You Won :). The Computers choice was" ,a)
p = p+1
a = random.choice(lst)
if i>9:
print("\n\nYour Win(s) =" , p)
print("Comuter's Win(s) =" , c)
if p>c:
print("Overall Winner : Player(You)")
elif p < c:
print("Overall Winner : Computer")
elif p == c:
print("Overall Winner : The Game has Draw")
else:
True
print("Do You Want to play again ? Yes(1) , No(2) :")
z = input()
if z == "1":
i = 0
r = 1
p = 0
c = 0
continue
elif z == "2":
break
else:
print("You entered a wrong Charecter Game ending...")
break
else:
continue
elif a == "Gun":
print("Sorry You Lost :( .The computers choice was",a)
c = c+1
a = random.choice(lst)
if i>9:
print("\n\nYour Win(s) =" , p)
print("Comuter's Win(s) =" , c)
if p>c:
print("Overall Winner : Player(You)")
elif p < c:
print("Overall Winner : Computer")
elif p == c:
print("Overall Winner : The Game has Draw")
else:
True
print("Do You Want to play again ? Yes(1) , No(2) :")
z = input()
if z == "1":
i = 0
r = 1
p = 0
c = 0
continue
elif z == "2":
break
else:
print("You entered a wrong Charecter Game ending...")
break
else:
continue
else:
True
elif q == "w":
if a == "Snake":
print("Sorry You Lost :( .The computers choice was",a)
c = c+1
a = random.choice(lst)
if i>9:
print("\n\nYour Win(s) =" , p)
print("Comuter's Win(s) =" , c)
if p>c:
print("Overall Winner : Player(You)")
elif p < c:
print("Overall Winner : Computer")
elif p == c:
print("Overall Winner : The Game has Draw")
else:
True
print("Do You Want to play again ? Yes(1) , No(2) :")
z = input()
if z == "1":
i = 0
r = 1
p = 0
c = 0
continue
elif z == "2":
break
else:
print("You entered a wrong Charecter Game ending...")
break
else:
continue
elif a == "Gun":
print("You Won :). The Computers choice was" ,a)
p = p+1
a = random.choice(lst)
if i>9:
print("\n\nYour Win(s) =" , p)
print("Comuter's Win(s) =" , c)
if p>c:
print("Overall Winner : Player(You)")
elif p < c:
print("Overall Winner : Computer")
elif p == c:
print("Overall Winner : The Game has Draw")
else:
True
print("Do You Want to play again ? Yes(1) , No(2) :")
z = input()
if z == "1":
i = 0
r = 1
p = 0
c = 0
continue
elif z == "2":
break
else:
print("You entered a wrong Charecter Game ending...")
break
else:
continue
elif a == "Water":
print("Draw. The Computers choice was" ,a)
a = random.choice(lst)
if i >9:
print("\n\nYour Win(s) =" , p)
print("Comuter's Win(s) =" , c)
if p>c:
print("Overall Winner : Player(You)")
elif p < c:
print("Overall Winner : Computer")
elif p == c:
print("Overall Winner : The Game has Draw")
else:
True
print("Do You Want to play again ? Yes(1) , No(2) :")
z = input()
if z == "1":
i = 0
r = 1
p = 0
c = 0
continue
elif z == "2":
break
else:
print("You entered a wrong Charecter Game ending...")
break
else:
continue
else:
True
elif q == "g":
if a == "Snake":
print("You Won :). The Computers choice was" ,a)
p = p+1
a = random.choice(lst)
if i>9:
print("\n\nYour Win(s) =" , p)
print("Comuter's Win(s) =" , c)
if p>c:
print("Overall Winner : Player(You)")
elif p < c:
print("Overall Winner : Computer")
elif p == c:
print("Overall Winner : The Game has Draw")
else:
True
print("Do You Want to play again ? Yes(1) , No(2) :")
z = input()
if z == "1":
i = 0
r = 1
p = 0
c = 0
continue
elif z == "2":
break
else:
print("You entered a wrong Charecter Game ending...")
break
else:
continue
elif a == "Water":
print("Sorry You Lost :( .The computers choice was",a)
c = c+1
a = random.choice(lst)
if i>9:
print("\n\nYour Win(s) =" , p)
print("Comuter's Win(s) =" , c)
if p>c:
print("Overall Winner : Player(You)")
elif p < c:
print("Overall Winner : Computer")
elif p == c:
print("Overall Winner : The Game has Draw")
else:
True
print("Do You Want to play again ? Yes(1) , No(2) :")
z = input()
if z == "1":
i = 0
r = 1
p = 0
c = 0
continue
elif z == "2":
break
else:
print("You entered a wrong Charecter Game ending...")
break
else:
continue
elif a == "Gun":
print("Draw. The Computers choice was" ,a)
a = random.choice(lst)
if i >9:
print("\n\nYour Win(s) =" , p)
print("Comuter's Win(s) =" , c)
if p>c:
print("Overall Winner : Player(You)")
elif p < c:
print("Overall Winner : Computer")
elif p == c:
print("Overall Winner : The Game has Draw")
else:
True
print("Do You Want to play again ? Yes(1) , No(2) :")
z = input()
if z == "1":
i = 0
r = 1
p = 0
c = 0
continue
elif z == "2":
break
else:
print("You entered a wrong Charecter Game ending...")
break
else:
continue
else:
True
else:
print("You entered wrong chacreter.Game ending")
break
print("\nThank You For Using Made By Tanush Chauhan :)")
2. Healthy Programmer
# importing modules
from pygame import mixer #pip install pygame
from datetime import datetime
import time
#All Fuctions
def playmusic(file, stopper):
mixer.init()
mixer.music.load(file)
mixer.music.play()
while True:
input_of_user = input()
if input_of_user == stopper:
mixer.music.stop()
break
def checktime():
x = time.strftime('%H%M')
if x > '0859' and x < '1701':
return True
else:
return False
def log(messege):
with open("logs.txt", "a") as f:
f.write(f"{datetime.now()} : {messege} \n")
# To Check if Office has started or not
if checktime():
#Variable defined
waterstarting = time()
eyesstarting = time()
physicalstarting = time()
watertime = 1200
physicaltime = 1800
eyestime = 2700
timeforsleep = 60 # the programme will check after every 1 minute
#Main Logic
while True:
if checktime(): #To Check If office is over or not
if time() - waterstarting > watertime:
print("Water Drinking time. Enter 'drank' to stop the alarm.")
playmusic('water.mp3', 'drank')
waterstarting = time()
log("Drank Water")
if time() - eyesstarting >eyestime:
print("Eye exercise time. Enter 'doneeyes' to stop the alarm.")
playmusic('eyes.mp3', 'doneeyes')
eyesstarting = time()
log("Eyes Relaxed at")
if time() - physicalstarting > physicaltime:
print("Physical Activity Time. Enter 'donephy' to stop the alarm.")
playmusic('physical.mp3', 'donephy')
physicalstarting = time()
log("Physical Activity done at")
time.sleep(timeforsleep) # the programme will check after every 1 minute
else:
print("I think your office is over now have a good day :)")
else:
print("I don't Think its Office time Enjoy :)")
3. Lcm/Hcf Calculator
print("By Tanush Chauhan")
while (True):
print("Do you want Operration on 2 numbers(1) or 3 numbers(2)")
z = int(input())
print("Enter Numbers to Calculate LCM and Hcf(only for 2 numbers)")
if z == 1:
a=int(input("Enter First number "))
b=int(input("Enter Second number "))
for m in range (1, a *b +1):
if m%a ==0 and m%b ==0 :
print("LCM of the numbers is ", m)
break
Hcf = (a*b)/m
print("Hcf of the numbers is", Hcf)
elif z == 2 :
a=int(input("Enter First number "))
b=int(input("Enter Second number "))
c = int(input("Enter Third number "))
for m in range (1, a *b*c +1):
if m%a ==0 and m%b ==0 and m%c == 0:
print("LCM of number is ", m)
break
print("Enter 1 for continue and 2 for exit")
d = int(input())
if d == 1:
continue
elif d == 2:
break
else:
continue
~~~~End~~~~