Skip to content
TheChatArchiveThe Chat Archive
Mistralmistral-medium-2505· Mistral AIHugging Face LMArena Human Preference 140K

code me a prime number shower python script

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Amazon Novaamazon.nova-pro-v1:0’s answer.
  1. User

    code me a prime number shower python script

  2. Mistral Assistant

    Prime Number Generator in Python

    Here's a Python script that generates and displays prime numbers up to a given limit:

    def is_prime(n):
        """Check if a number is prime."""
        if n <= 1:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        for i in range(3, int(n**0.5) + 1, 2):
            if n % i == 0:
                return False
        return True
    
    def display_primes(limit):
        """Display all prime numbers up to the given limit."""
        print(f"Prime numbers up to {limit}:")
        primes = []
        for num in range(2, limit + 1):
            if is_prime(num):
                primes.append(num)
        print(primes)
        print(f"Total primes found: {len(primes)}")
    
    def main():
        print("Prime Number Generator")
        print("----------------------")
    
        while True:
            try:
                limit = int(input("Enter the upper limit (or 0 to exit): "))
                if limit == 0:
                    print("Exiting the program...")
                    break
                if limit < 2:
                    print("Please enter a number greater than 1.")
                    continue
                display_primes(limit)
            except ValueError:
                print("Please enter a valid integer.")
    
    if __name__ == "__main__":
        main()
    

    How to Use This Script:

    1. Run the script in a Python environment
    2. Enter an upper limit when prompted
    3. The script will display all prime numbers up to that limit
    4. Enter 0 to exit the program

    Features:

    • Efficient prime checking using trial division up to the square root
    • Input validation to handle non-integer inputs
    • Option to exit the program
    • Displays both the list of primes and the count

    Example Output:

    Prime Number Generator
    ----------------------
    Enter the upper limit (or 0 to exit): 20
    Prime numbers up to 20:
    [2, 3, 5, 7, 11, 13, 17, 19]
    Total primes found: 8
    

    You can modify the script to suit your specific needs, such as changing the output format or adding additional functionality.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.