Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
python_study_note_while loop
### 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))
run
|
edit
|
history
|
help
0
1.py
Moore Voting Algorithm
Homework exercise
binary
Return nth fibonacci number using memoization
Lesson 8 updated
Insertion sort
Ortalama
LinkedList implementation
Ugly number