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
l=[i for i in range(1,101) if i%3==0 or i%5==0] | |
print(l) |
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
l = ['Welcome','to','ComputerTutor','Python','Revision'] | |
m = 0 | |
w = None | |
for i in range(len(l)): | |
if len(l[i])>m: | |
word=l[i] | |
m=len(l[i]) | |
print('Longest word present in list is:', word) |
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
l = input('Enter a List: ').split() # input().split() returns the list | |
l = l[len(l)-1:] + l[:-1] # last element being added at | |
#the start with the list slice that doesn’t contain the last element | |
print('Rotated list is::',l) |
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
s = input('Enter a sentence : ') | |
number_of_words = 1 | |
number_of_characters = len(s) | |
al_num = 0 | |
for i in s: | |
if i.isalnum(): | |
al_num += 1 | |
if i == ' ': # there is a space means there is another word | |
number_of_words += 1 | |
print('Number of words are', number_of_words) |
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
s = input('Enter a sentence : ') | |
number_of_words = 1 | |
number_of_characters = len(s) | |
al_num = 0 | |
for i in s: | |
if i.isalnum(): | |
al_num += 1 | |
if i == ' ': # there is a space means there is another word | |
number_of_words += 1 | |
print('Number of words are', number_of_words) |
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
L = list(map(int, input('Enter list of integers : ').split())) | |
M = list(map(int, input('Enter list of integers : ').split())) | |
if len(L) == len(M): | |
N = [L[i]+M[i] for i in range(len(L))] | |
print(N) |
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
number = input("Enter Phone number: ") | |
if len(number)==12: | |
if number[3]=='-' and number[7]=='-': | |
if(number[:3]+number[4:7]+number[8:]).isdigit(): | |
print('Phone number is valid') | |
else : | |
print("Phone number is invalid") | |
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 ath(f1,f2): | |
l=f1.readlines() | |
for line in l: | |
if 'Athlectics' in line: | |
f2.write(line) | |
f2.write('\n') | |
f1 = open('/content/Athletics_data.txt', 'r') | |
f2 = open('/content/Sports_data.txt', 'w') | |
ath(f1,f2) |
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
f=open('/content/Contacts.csv','r') | |
for line in f: | |
x=line.split() | |
print(x) |
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
f = open('Poem.txt', 'r') | |
c_to=0 | |
c_the=0 | |
for line in f: | |
c_to += line.count('to') | |
c_the += line.count('the') | |
print(c_to) | |
print(c_the) |