Skip to content

Instantly share code, notes, and snippets.

View 4k45hv3rm4's full-sized avatar
💻
If world were perfect . It Wouldn't be...

Aakash Verma 4k45hv3rm4

💻
If world were perfect . It Wouldn't be...
View GitHub Profile
@4k45hv3rm4
4k45hv3rm4 / primeApproach1.py
Last active March 27, 2019 21:53
Prime Number (Iterating through to N)
#input
N=int(input("Enter any number : "))
#iterate through
for i in range(2,N):
#Not a prime Condition
if (N%i==0):
print("Not a prime number")
break #TO STOP THE FOR LOOP ONCE , NOT PRIME DETECTED
else:
@4k45hv3rm4
4k45hv3rm4 / primeApproach2.py
Last active March 27, 2019 21:52
Prime Number upto N (Iterating through N/2 elments)
#input
N=int(input("Enter any number : "))
#iterate through
for i in range(2,N//2): #FLOOR DIVISON
#Not a prime Condition
if (N%i==0):
print("Not a prime number")
break #TO STOP THE FOR LOOP ONCE NOT PRIME DETECTED
else:
#approach1
Out[]:#approach1
Enter any number : 984607
Not a prime number
5.799290895462036
#approach2
out[]:
Enter any number : 984607
#input
N=int(input("Enter any number : "))
#iterate through
for i in range(2,int(N**0.5+1)): #Square root of N
#Not a prime Condition
if (N%i==0):
print("Not a prime number")
break
else:
N=int(input("Enter any number :"))
#function to check whether N is Prime
def isPrime(N):
#method is to test if n is divisible by 2 or 3
if (N%2 == 0 or N%3 == 0):
return False
# to check through all the numbers of form 6 k ± 1 ≤ n
i=5
while (i*i <=N):
if(N%i == 0 or N%(i+2) == 0):
@4k45hv3rm4
4k45hv3rm4 / Guess the Number Game.py
Last active March 30, 2019 13:30
Guess the Number Game
#Guess the Number Game
import random
print("Hello world!")
#Ask Name
Name = input("what is your Name ")
print("Well Hello! " + Name + " I am thinking a number between 1 to 20 ")
#Using Random Lirary Choose any number and save it into a variable
secretNumber = random.randint(1,20)
# Iterate through for 7 times:
@4k45hv3rm4
4k45hv3rm4 / word_guess.py
Last active August 24, 2019 16:27
code for word_guessing game in Python
import random
#list of words
word = ["lemon","mango","banana","apple"]
#ask Name
name=input("Enter Your name")
print(f"Hi {name} , Let's start the game")
# choice='y'
# while(choice == 'y'):
print("\n\n\n\t\t ***Word Guessing Game*** ")
@4k45hv3rm4
4k45hv3rm4 / word_guess1.py
Created August 24, 2019 16:32
first part
import random
#list of words
word = ["lemon","mango","banana","apple"]
#ask Name
name=input("Enter Your name")
print(f"Hi {name} , Let's start the game")
# choice='y'
# while(choice == 'y'):
print("\n\n\n\t\t ***Word Guessing Game*** ")
@4k45hv3rm4
4k45hv3rm4 / word_guess2.py
Created August 24, 2019 16:33
second part
#list to store wrong guessed_letters
wrong_list=[]
#generate random word
original_word=random.choice(word)
print(f"The word is of {len(original_word)} letters. ")
#create an empty list
guessed_word = []
for i in range(len(original_word)):
@4k45hv3rm4
4k45hv3rm4 / word_guess3.py
Created August 24, 2019 16:35
Third part
c=8
while(c):
c=c-1
#take input from user
guessed_letter = input("Guess the letter")
#check if guessed_letter is an alphabet
if not guessed_letter.isalpha():
print('Guess only a letter')
#check if guessed letter length is one or not