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('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) |
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
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) |
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
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() |
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
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 |
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 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 |
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 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)) |
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 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)) |
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
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)) |
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
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)) |
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 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)) |