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 |
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
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
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
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
number = int(input()) | |
counter =0 | |
while number > 0: | |
number = number//10 | |
print(number) | |
counter +=1 | |
print("number of digits :",counter) |
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
number = int(input("Enter your number \n")) | |
for i in range(2, number + 1): | |
if number % i == 0: | |
print(i, "is smallest divisor") | |
break |
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")) | |
for i in range(n): | |
for j in range(n): | |
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
a = int(input("Enter your number \n")) | |
b = int(input("Enter your number \n")) | |
res = max(a, b) | |
while res <= a * b: | |
if res % a == 0 and res % b == 0: | |
break | |
res += 1 | |
print(res) |
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 =int(input("Enter your number \n")) | |
b =int(input("Enter your number \n")) | |
small = min(a,b) | |
for i in range(1,small+1): | |
if (a%i ==0 and b% i ==0): | |
gcd =i | |
print(gcd) |
OlderNewer