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
n=5 | |
for i in range(n): | |
for j in range(n-i-1): | |
print(" ",end="") | |
for k in range(2*i+1): | |
print("*",end="") | |
print() | |
""" | |
* |
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
n = int(input("Enter your number \n")) | |
for i in range(n): | |
for j in range(n-i): | |
print('*', end="") | |
print() | |
''' | |
Output: |
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
for i in range(5): | |
for j in range(i+1): | |
print('*',end="") | |
print("") | |
''' | |
Output: |
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
x = 1 | |
y = 2 | |
# tuple unpacking can be used to swap the number | |
x, y = y, x | |
print("swapped value of x : ", x) | |
print("swapped value of y : ", y) |
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
sentence = "This is a common interview question" | |
def most_repeated_char(sentence): | |
character_freq = {} | |
for char in sentence: | |
if char in character_freq: | |
character_freq[char] += 1 | |
else: | |
character_freq[char] = 1 |
NewerOlder