Skip to content

Instantly share code, notes, and snippets.

from random import randint
def random_n_digit(n):
range_start = 10**(n-1)
range_end = (10**n)-1
return randint(range_start,range_end)
print('Random number of digit 3 is', random_n_digit(3))
print('Random number of digit 5 is', random_n_digit(5))
def minOne(x,y):
if x%10<y%10:
return x
elif (x%10)==(y%10):
return 'Both are Equal'
else:
return y
print(minOne(85,16))
print(minOne(89,79))
def func(x, y):
d = (y-x)//3 # divides the difference in 3 equal parts
return [x, x+d, x+2*d, y] # returns the series as a list
print(func(1, 9))
print(func(4, 8))
print(func(4, 10))
print(func(1, 7))
def func_start_A(l): # function to count lines starting with ‘A’
c = 0 # c is the count of such lines
for line in l:
if line.startswith('A'):
c += 1
return c
f1 = open('LINES.txt', 'r')
l = f1.readlines() # creates a list of all the lines in the file
f1 = open('LOWER.txt', 'w')
f2 = open('UPPER.txt', 'w')
f3 = open('OTHERS.txt', 'w')
c = True
while c:
c = input('Enter a character to write or exit to terminate the program : ')
if c=='exit':
break
elif c.islower(): # checks for lower character
name1 = input("Enter file to be read from:")
name2 = input("Enter file to be appended to:")
fin= open (name1,'r')
data2=fin.read()
fin.close()
fout= open(name2,"a")
fout.write(data2)
fout.close()
print('\nWelcome to Computer Tutor!')
f1_name = input('\nEnter the first (txt) file name:')
f2_name = input ('\nEnter the second (txt) file name:')
with open(f1_name) as f:
with open(f2_name,"w") as f1:
for line in f:
f1.write(line)
f = open('Article.txt','r')
c_up=0
ch = f.read(1)
while ch:
ch=f.read(1)
if ch.isupper():
c_up+=1
print("Number of Uppercase alphabets is/are:",c_up)
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)
f=open('/content/Contacts.csv','r')
for line in f:
x=line.split()
print(x)