Hackerrank Problems #1 solved in Python
Problems solved in Python
Hackerrank
Hello Programmer's
Here i have submit question from hackerrank
I solved this
Check my code, Submit your code if you find easy and simple way.
Copy that Py Code and Paste Below mention website and run it...
website: https://repl.it/languages/python3
The Utopian Tree goes through 2 cycles of growth every year. Each spring, it doubles in height. Each summer, its height increases by 1 meter.
Laura plants a Utopian Tree sapling with a height of 1 meter at the onset of spring. How tall will her tree be after growth cycles?
For example, if the number of growth cycles is , the calculations are as follows:
Period Height
0 1
1 2
2 3
3 6
4 7
5 14
CODE 1:
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the utopianTree function below.
def utopianTree(n):
if n >= 0:
if n == 0:
return 1
elif n == 1:
return 2
else:
height = 1
for i in range(1,n+1):
if i % 2 != 0:
height += height
else:
height += 1
return height
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
for t_itr in range(t):
n = int(input())
result = utopianTree(n)
fptr.write(str(result) + '\n')
fptr.close()
-------
By
PyKAR
Comments
Post a Comment