Created
November 2, 2018 19:13
-
-
Save piyush2896/584a18e2d7703e5042fd13e9c4f2a368 to your computer and use it in GitHub Desktop.
Assignment code for https://predictiveprogrammer.com/intro-to-programming-with-python-4/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_armstrong(num): | |
cube_sum = 0 | |
temp = num | |
while temp >= 0: | |
digit = temp % 10 | |
cube_sum = cube_sum + digit ** 3 | |
temp = temp / 10 | |
return cube_sum == num |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_max_and_index(li): | |
max = li[0] | |
index = 0 | |
for i in range(1, len(li)): | |
if li[i] > max: | |
max = li[i] | |
index = i | |
return max, index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum_list(input_list): | |
total = input_list[0] | |
if len(input_list) < 2: | |
return total | |
for ele in input_list[1:]: | |
total = total + ele | |
return total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment