Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aa7dc5b

Browse files
Update Five.py
1 parent a5cb81d commit aa7dc5b

File tree

1 file changed

+2
-7
lines changed
  • Medium-Questions/05-algorithm-odd/Python

1 file changed

+2
-7
lines changed

‎Medium-Questions/05-algorithm-odd/Python/Five.py‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
import sys
22

3-
# this function check is a number is even or not
43
def is_even(number):
54
if (number % 2 == 0):
65
return True
76
return False
87

98

10-
# get input and check is positive number or not
11-
n = int(input("Enter numbr: "))
9+
n = int(input("Enter number: "))
1210
if (n < 0):
1311
print("Number must be positive :(")
1412
sys.exit(1)
1513

16-
# print first number in iutput
1714
print(n,end="-> ")
1815

1916
while (True):
2017
if (n == 1):
2118
print("end")
2219
sys.exit(0)
2320

24-
# send number to even function and if number is even so we divided by 2
25-
# and continue this loop
2621
if (is_even(n)):
2722
n //= 2
2823
print(n,end="-> ")
2924
continue
30-
# else we just multiplies it by 3 and add 1 to it
25+
3126
n *= 3
3227
n += 1
3328
print(n,end="-> ")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /