Joel  Hawkins

Joel Hawkins

1586288280

Python Program to Print N Prime Number

Python Program To Print Numbers From 1 to N Using For Loop
Python Program to find Prime Number using For Loop
Sum of prime numbers in python using for loop
Python Program To Print Numbers From 1 to N Using While Loop

Python Program To Print Numbers From 1 to N Using For Loop

# Python Program to print n prime number using for loop
  
Number = int(input(" Please Enter any Number: "))
 
print("Prime numbers between", 1, "and", Number, "are:")
 
for num in range(1, Number + 1):
   # all prime numbers are greater than 1
   if num > 1:
       for i in range(2, num):
           if (num % i) == 0:
               break
       else:
           print(num)

Output

Please Enter any Number:  25 
Prime numbers between 1 and 25 are: 
2 3 5 7 11 13 17 19 23 

Python Program to find Prime Number using For Loop

# Python Program to Check A given Number is Prime Or Not
 Num = int(input(" Please Enter any Number: "))
 count = 0
 for i in range(2, (Num//2 + 1)):
     if(Num % i == 0):
         count = count + 1
         break
 if (count == 0 and Num != 1):
     print(" %d is a Prime Number" %Num)
 else:
     print(" %d is not a Prime Number" %Num)

Output

Please Enter any Number:  50  
50 is not a Prime Number

Sum of prime numbers in python using for loop

# Python Program to print n prime number using for loop
  
max = int(input("Find sum of prime numbers upto : "))
 
sum = 0
 
for num in range(2, max + 1):
 
    i = 2
     
    for i in range(2, num):
        if (int(num % i) == 0):
            i = num
            break;
 
    #If the number is prime then add it.
    if i is not num:
        sum += num
 
print("\nSum of all prime numbers upto", max, ":", sum)

Output

Find sum of prime numbers upto :  25 
Sum of all prime numbers upto 25 : 98   

Python Program To Print Numbers From 1 to N Using While Loop

# Python Program to print Prime Numbers from 1 to N
  
max = int(input(" Please Enter Any Number: "))
 
Number = 1
 
print("Prime numbers between", 1, "and", max, "are:")
 
while(Number <= max):
    count = 0
    i = 2
     
    while(i <= Number//2):
        if(Number % i == 0):
            count = count + 1
            break
        i = i + 1
 
    if (count == 0 and Number != 1):
        print(" %d" %Number, end = '  ')
    Number = Number  + 1

Output

Please Enter Any Number:  15 
Prime numbers between 1 and 15 are:  
2   3   5   7   11   13  

#python #programming

What is GEEK

Buddha Community

Python Program to Print N Prime Number
Ray  Patel

Ray Patel

1619518440

top 30 Python Tips and Tricks for Beginners

Welcome to my Blog , In this article, you are going to learn the top 10 python tips and tricks.

1) swap two numbers.

2) Reversing a string in Python.

3) Create a single string from all the elements in list.

4) Chaining Of Comparison Operators.

5) Print The File Path Of Imported Modules.

6) Return Multiple Values From Functions.

7) Find The Most Frequent Value In A List.

8) Check The Memory Usage Of An Object.

#python #python hacks tricks #python learning tips #python programming tricks #python tips #python tips and tricks #python tips and tricks advanced #python tips and tricks for beginners #python tips tricks and techniques #python tutorial #tips and tricks in python #tips to learn python #top 30 python tips and tricks for beginners

Ray  Patel

Ray Patel

1619510796

Lambda, Map, Filter functions in python

Welcome to my Blog, In this article, we will learn python lambda function, Map function, and filter function.

Lambda function in python: Lambda is a one line anonymous function and lambda takes any number of arguments but can only have one expression and python lambda syntax is

Syntax: x = lambda arguments : expression

Now i will show you some python lambda function examples:

#python #anonymous function python #filter function in python #lambda #lambda python 3 #map python #python filter #python filter lambda #python lambda #python lambda examples #python map

Perfect Number Program In Python: How to check if a number is perfect or not?

Introduction

A number is said to be the perfect number if the sum of its proper divisors (not including the number itself) is equal to the number.

To get a better idea let’s consider an example, proper divisors of 6 are 1, 2, 3. Now the sum of these divisors is equal to 6 (1+2+3=6), so 6 is said to be a perfect number. Whereas if we consider another number like 12, proper divisors of 12 are 1, 2, 3, 4, 6. Now the sum of these divisors is not equal to 12, so 12 is not a perfect number.

Programming in Python is relatively simpler and more fun when compared to other languages because of its simpler syntax, good readability. Now that we are clear with the concept of perfect number let’s write a python program to check if a number is a perfect number or not. Let’s build a python code for checking if the given user input is a perfect number or not and explore the fun in coding with python.

#data science #how to check if a number is perfect #perfect number #perfect number in python #perfect number program in python #python

Ray  Patel

Ray Patel

1619607900

Perfect Number Program In Python: How to check if a number is perfect or not?

Introduction

A number is said to be the perfect number if the sum of its proper divisors (not including the number itself) is equal to the number.

To get a better idea let’s consider an example, proper divisors of 6 are 1, 2, 3. Now the sum of these divisors is equal to 6 (1+2+3=6), so 6 is said to be a perfect number. Whereas if we consider another number like 12, proper divisors of 12 are 1, 2, 3, 4, 6. Now the sum of these divisors is not equal to 12, so 12 is not a perfect number.

Programming in Python is relatively simpler and more fun when compared to other languages because of its simpler syntax, good readability. Now that we are clear with the concept of perfect number let’s write a python program to check if a number is a perfect number or not. Let’s build a python code for checking if the given user input is a perfect number or not and explore the fun in coding with python.

#data science #how to check if a number is perfect #perfect number #perfect number in python #perfect number program in python #python

August  Larson

August Larson

1624930726

Automating WhatsApp Web with Alright and Python

Alright is a python wrapper that helps you automate WhatsApp web using python, giving you the capability to send messages, images, video, and files to both saved and unsaved contacts without having to rescan the QR code every time.

Why Alright?

I was looking for a way to control and automate WhatsApp web with Python; I came across some very nice libraries and wrappers implementations, including:

  1. pywhatkit
  2. pywhatsapp
  3. PyWhatsapp
  4. WebWhatsapp-Wrapper

So I tried

pywhatkit, a well crafted to be used, but its implementations require you to open a new browser tab and scan QR code every time you send a message, no matter if it’s the same person, which was a deal-breaker for using it.

I then tried

pywhatsapp,which is based onyowsupand require you to do some registration withyowsupbefore using it of which after a bit of googling, I got scared of having my number blocked. So I went for the next option.

I then went for WebWhatsapp-Wrapper. It has some good documentation and recent commits so I had hoped it is going to work. But It didn’t for me, and after having a couple of errors, I abandoned it to look for the next alternative.

PyWhatsapp by shauryauppal, which was more of a CLI tool than a wrapper, surprisingly worked. Its approach allows you to dynamically send WhatsApp messages to unsaved contacts without rescanning QR-code every time.

So what I did is refactoring the implementation of that tool to be more of a wrapper to easily allow people to run different scripts on top of it. Instead of just using it as a tool, I then thought of sharing the codebase with people who might struggle to do this as I did.

#python #python-programming #python-tutorials #python-programming-lists #selenium #python-dev-tips #python-developers #programming #web-monetization