GithubHelp home page GithubHelp logo

parisaarbab / happy-prime-numbers Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 4 KB

classifies numbers into one of four categories: Happy Prime, Sad Prime, Happy Non-Prime, or Sad Non-Prime, based on their primality and happiness status.

Python 100.00%

happy-prime-numbers's Introduction

Happy-prime-numbers

classifies numbers into one of four categories: Happy Prime, Sad Prime, Happy Non-Prime, or Sad Non-Prime, based on their primality and happiness status. This Python program classifies numbers into one of four categories: Happy Prime, Sad Prime, Happy Non-Prime, or Sad Non-Prime, based on their primality and happiness status.

Primality Check: The is_prime function determines if a number is prime. Numbers less than 2 are not prime. The function efficiently checks divisibility for numbers greater than 3, ruling out non-prime numbers early.

Happiness Check: The is_happy function checks if a number is a happy number. A number is happy if the sum of the squares of its digits repeatedly leads to 1. The function uses a set to track visited numbers to detect loops.

Classification: The classify_number function uses is_prime and is_happy to classify a number into one of four categories: Happy Prime (a prime number that is also happy), Sad Prime (a prime number that is not happy), Happy Non-Prime (a non-prime number that is happy), or Sad Non-Prime (a non-prime number that is not happy).

User Interaction: The program prompts the user to enter a positive integer and uses the classify_number function to classify it, printing the result. The loop continues until the user enters '0' to exit. It handles invalid inputs gracefully, prompting the user to enter a positive integer in case of a ValueError.

This code combines mathematical concepts of primality and happiness of numbers with interactive input to provide an educational tool that explores number theory properties.

happy-prime-numbers's People

Contributors

parisaarbab avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.