Skip to content

Instantly share code, notes, and snippets.

l=[i for i in range(1,101) if i%3==0 or i%5==0]
print(l)
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)
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)
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)
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)
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)
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")
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)
f=open('/content/Contacts.csv','r')
for line in f:
x=line.split()
print(x)
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)