Skip to content

Instantly share code, notes, and snippets.

@Natgho
Created November 21, 2022 22:08
Show Gist options
  • Save Natgho/e57268cd48a2a3ae365be1065a9d2c8a to your computer and use it in GitHub Desktop.
Save Natgho/e57268cd48a2a3ae365be1065a9d2c8a to your computer and use it in GitHub Desktop.
PowSample
value = int(input("Enter maximum value: "))
nested_list = []
result = []
if not 0 < value < 99:
raise Exception("The value N should be between 1-99")
for val in range(1, value + 1):
tmp_list = []
for sub_val in range(val):
tmp_list.append(val)
nested_list.append(tmp_list)
# alttaki if else ile yorum satırındaki append aynı işi yapar, 12. satırdaki daha havalı durur :)
# result.append(pow(val, val) if val % 2 else sum(tmp_list))
if val % 2:
result.append(pow(val, val))
else:
result.append(sum(tmp_list))
print("The nested list:", nested_list)
print("Result:", result)
"""
Enter maximum value: 8
The nested list: [[1], [2, 2], [3, 3, 3], [4, 4, 4, 4], [5, 5, 5, 5, 5], [6, 6, 6, 6, 6, 6], [7, 7, 7, 7, 7, 7, 7], [8, 8, 8, 8, 8, 8, 8, 8]]
Result: [1, 4, 27, 16, 3125, 36, 823543, 64]
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment