This file contains hidden or 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
nums = [5, 7, 9, 10] | |
squares = [x**2 for x in nums] |
This file contains hidden or 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
a = 5 | |
b = 3 | |
a, b = b, a |
This file contains hidden or 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 is_palindrome(text: str) -> bool: | |
return text == text[::-1] |
This file contains hidden or 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 is_armstrong(number: int) -> bool: | |
digits = str(number) | |
num_digits = len(digits) | |
total = sum(int(digit) ** num_digits for digit in digits) | |
return total == number | |
num = int(input("Enter a number: ")) | |
if is_armstrong(num): | |
print(f"{num} is an Armstrong number.") | |
else: |
This file contains hidden or 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 factorial(x): | |
if x == 1: | |
return 1 | |
else: | |
return x * factorial(x-1) | |
print(factorial(5)) |
This file contains hidden or 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 isPrime(x): | |
if x < 2: | |
return False | |
elif x == 2: | |
return True | |
for n in range(2, x): | |
if x % n ==0: | |
return False | |
return True |
This file contains hidden or 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
print("Hello World!") |