Skip to content

Instantly share code, notes, and snippets.

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)
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()
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
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
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 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))
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 nthroot(x,n=2):
return round(x**(1/n),2)
print("Nth root of",10, 'for n=3 is',nthroot(10,3))
print("Square root of",30,"is", nthroot(30))
def equ_len(x,y):
return len(x)==len(y)
a=input('Enter first string:')
b=input('Enter second string:')
print('Length of', a, 'is equal to length of',b,'is', equ_len(a,b))
from random import randint
def random(x,y):
return randint(x,y)
print("Three random numbers are: ", random(10,50),random(2,10),random(500,600))