This file contains 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
#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: |
This file contains 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
#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: |
This file contains 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
#approach1 | |
Out[]:#approach1 | |
Enter any number : 984607 | |
Not a prime number | |
5.799290895462036 | |
#approach2 | |
out[]: | |
Enter any number : 984607 |
This file contains 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
#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: |
This file contains 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
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): |
This file contains 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
#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: |
This file contains 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 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*** ") |
This file contains 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 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*** ") |
This file contains 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
#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)): |
This file contains 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
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 |
OlderNewer