Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
python_study_note_while loop
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
### question 1 def print_prime_factors(number): factor = 2 while factor <= number: if number % factor == 0: print(factor) number = number / factor else: factor += 1 return "Done" print_prime_factors(100) ### question 2 def is_power_of_two(x): # Check if the number can be divided by two without a remainder while x % 2 == 0 and x!=0: x = x / 2 # If after dividing by two the number is 1, it's a power of two if x == 1: return True return False print(is_power_of_two(0)) # Should be False print(is_power_of_two(1)) # Should be True print(is_power_of_two(8)) # Should be True print(is_power_of_two(9)) # Should be False ### question 3 def sum_divisors(n): sum, num = 0, 1 while num < n: if n % num == 0: sum += num num += 1 return sum print(sum_divisors(36))
[
+
]
Show input
Absolute running time: 0.14 sec, cpu time: 0.02 sec, memory peak: 8 Mb, absolute service time: 0,27 sec
edit mode
|
history
|
discussion
2 2 5 5 False True True False 55