Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
prime_nonprime_count.py
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
def isPrime(n): p=1 if n==1: p=0 else: for i in range(2,n): if n%i==0: p=0 if p==1: return True else: return False def count(lst): prime=0 nprime=0 for e in lst: if isPrime(e): prime+=1 else: nprime+=1 return prime,nprime p,np=count([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]) print('prime_count {} and non prime_count {}'.format(p,np))
2 10 20
[
-
]
Show input
Absolute running time: 0.23 sec, cpu time: 0.21 sec, memory peak: 6 Mb, absolute service time: 0,23 sec
edit mode
|
history
|
discussion
prime_count 8 and non prime_count 12