IT1002 22bsmi01
IT1002 22bsmi01
Chapter 2
Q1.
print("Name : Anwarul Islam Utso")
print("Address : Khamaria, IIITDM Jabalpur - 482005")
print("Phone Number : +91-98740XXXX")
print("College Major : Smart Manufacturing")
Q2.
x = int(input('Enter the projected amount of total sales'))
print("Predicted Profits =",(x*0.23))
Q3.
x = int(input('Enter the total square feet of land '))
print("Total acres =",(x/43560))
Q4.
i1=int(input("Enter the amount for item1 "))
i2=int(input("Enter the amount for item2 "))
i3=int(input("Enter the amount for item3 "))
i4=int(input("Enter the amount for item4 "))
i5=int(input("Enter the amount for item5 "))
subtotal = i1+i2+i3+i4+i5
tax = int(0.07*(subtotal))
print("Subtotal =",subtotal)
print("Sales Tax=",tax)
print("Total =",(subtotal+tax))
Q5.
speed = 70
print("Speed of car = 70 Miles per hour")
print("Distance travelled in 6 hours =",6*speed,"Miles")
print("Distance travelled in 10 hours =",10*speed,"Miles")
print("Distance travelled in 15 hours =",15*speed,"Miles")
Q6.
x = int(input("Enter the amount of a purchase "))
st = int(0.05*x)
ct = int(0.025*x)
print("State tax =",st)
print("Country tax =",ct)
print("Total =",(x+st+ct))
Q7.
m = int(input("Enter number of miles driven "))
g = int(input("Enter gallons of gas used "))
mpg = m/g
print("MPG =",mpg)
Q8.
x = int(input("Enter the charge for the food "))
tip = 0.18*x
tax = 0.07*x
print("Charge for food = ",x)
print("Tip = ",tip)
print("State tax = ",tax)
print("Total =",(x+tip+tax))
Q9.
c = int(input("Enter a temperature in Celsius "))
f=((9/5)*c)+32
print("Temperature in Fahrenheit",f)
Q10.
n = int(input("Enter how many cookies you want to make "))
print((1.5/48)*n,"cups of sugar")
print((1/48)*n,"cups of butter")
print((2.75/48)*n,"cups of flour")
Chapter 3
Q1.
x = int(input("Enter a numnber in range 1 to 7 "))
if(x==1):
print("Monday")
elif(x==2):
print("Tuesday")
elif(x==3):
print("Wednesday")
elif(x==4):
print("Thursday")
elif(x==5):
print("Friday")
elif(x==6):
print("Saturday")
elif(x==7):
print("Sunday")
else:
print("Number out of range")
Q2.
l1 = int(input("Enter length & breadth of 1st rectangle "))
b1 = int(input())
l2 = int(input("Enter length & breadth of 2nd rectangle "))
b2 = int(input())
a1=l1*b1
a2=l2*b2
if(a1>a2):
print("1st rectangle has more area")
elif(a2>a1):
print("1st rectangle has more area")
else:
print("Equal areas")
Q3.
x = int(input("Enter a person’s age "))
if(x<=1):
print("He or she is infant")
elif(x>1 and x<13):
print("He or she is child")
elif(x>=13 and x<20):
print("He or she is teenager")
else:
print("He or she is adult")
Q4.
x = int(input("Enter a number within the range of 1 through 10
"))
if(x==1):
print("I")
elif(x==2):
print("II")
elif(x==3):
print("III")
elif(x==4):
print("IV")
elif(x==5):
print("V")
elif(x==6):
print("VI")
elif(x==7):
print("VII")
elif (x == 8):
print("VIII")
elif (x == 9):
print("IX")
elif (x == 10):
print("X")
else:
print("Number out of range")
Q5.
mass = int(input("Enter an object’s mass "))
weight = mass*9.8
print("Weight of object =",weight,"N")
if(weight>500):
print("It is too heavy")
elif(weight<100):
print("It is too light")
Q6.
mon = int(input("Enter a month (in numeric form) "))
day = int(input("Enter a day "))
year = int(input("Enter a two-digit year "))
if((mon*day)==year):
print("Magic")
else:
print("Not magic")
Q7.
color1 = input("Enter the names of two primary colors to mix")
color2 = input();
if(color1=="red" or color1=="yellow" or color1=="blue"):
if(color2=="red" or color2=="yellow" or color2=="blue"):
if (color1 == "red" and color2 == "blue"):
print("purple")
if (color2 == "red" and color1 == "blue"):
print("purple")
if (color1 == "red" and color2 == "yellow"):
print("orange")
if (color2 == "red" and color1 == "yellow"):
print("orange")
if (color1 == "blue" and color2 == "yellow"):
print("green")
if (color2 == "blue" and color1 == "yellow"):
print("green")
else:
print("Error")
else:
print("Error")
Q8.
x = int(input("Enter the number of people attending the cookout
"))
y = int(input("Enter the number of hot dogs each person "))
n = x*y
hd=n/10
hdb=n/8
if((hd-int(hd))!=0):
hd=int(hd)+1
if((hdb-int(hdb))!=0):
hdb=int(hdb)+1
print("Min no of hot dog packages required =",hd)
print("Min no of hot dog buns packages required =",hdb)
print("Number of hot dogs that will be left over =",(hd*10)-n)
print("Number of hot dog buns that will be left over =",(hdb*8)-
n)
Q9.
x = int(input("Enter a pocket number "))
if(x>=1 and x<=36):
if(x==0):
print("Green")
if(x>=1 and x<=10):
if(x%2==0):
print("Black")
else:
print("Red")
if (x >= 11 and x <= 18):
if (x % 2 == 0):
print("Red")
else:
print("Black")
if (x >= 19 and x <= 28):
if (x % 2 == 0):
print("Black")
else:
print("Red")
if (x >= 29 and x <= 36):
if (x % 2 == 0):
print("Red")
else:
print("Black")
else:
print("Error")
Q10.
x = int(input("Enter the number of coins required to make exactly
one dollar "))
p = int(input("Enter the number of pennies, nickels, dimes, and
quarters "))
n = int(input())
d = int(input())
q = int(input())
total = p + (n*5) + (d*10) + (q*25)
if(total == 100):
print("Congratulations !!")
elif(total>100):
print("Amount is more than one dollar")
elif(total<100):
print("Amount is less than one dollar")
Chapter 4
Q1.
total=0
for i in range(5):
print("Enter the no of bugs on day",i+1)
x=int(input())
total+=x
print("Total number of bugs collected =",total)
Q2.
for i in (10,15,20,25,30):
print("Calories burned in",i,"minutes =",(4.2*i))
Q3.
x = int(input("Enter the amount that he or she has budgeted for a
month"))
n = int(input("No of expenses"))
total=0
for i in range(n):
print((i+1),"Expense")
ex=int(input())
total+=ex
if(total>x):
print("Over budget")
else:
print("Under budget")
Q4.
speed = int(input("Enter speed of vehicle in mph? "))
hour = int(input("How many hours has it traveled? "))
for i in range(hour):
print(speed*(i+1))
Q5.
y = int(input("Enter the no of years "))
n=0;
total=0;
for i in range(y):
for j in range(12):
n+=1
inch = int(input("Enter the rainfall"))
total+=inch
print("Number of months =",n)
print("Total rainfall =",total)
print("Avg Rainfall =",total/n)
Q6.
for i in range(21):
print(i,"Celsius =",round(((9/5)*i)+32,2),"Fahrenheit")
Q7.
n = int(input("Enter the number of days "))
salary=1
total=0
for i in range(n):
print("Day",(i+1),"Salary =",salary)
total+=salary
salary*=2
print("Total in",n,"days =",total/100,"Dollars")
Q8.
print("Enter a series of positive numbers & a negative to end ")
i=0
total=0
while (True):
i = int(input())
if(i>=0):
total+=i
else:
break
print("Sum =",total)
Q9.
for i in range(25):
print("Rise in Year",(i+1),"=",round((i+1)*1.6,2),"mm")
Q10.
fees = 8000
for i in range(5):
print("Tuition fees for year",(i+1),"= $",round(fees,2))
inc = 0.03 * fees
fees+=inc
Chapter 5
Q1.
def conv(x):
return(x * 0.6214)
a = int(input("Enter the distance in Km "))
print(conv(a),'Miles')
Q2.
def state(x):
return (0.05*x)
def country(x):
return (0.025*x)
amt = int(input("Enter the amount of purchase "))
tax = state(amt) + country(amt)
totalamt = amt + tax
print("Amount of purchase = ",amt)
print("State tax = ",state(amt))
print("Country tax = ",country(amt))
print("Total Tax = ",tax)
print("Total Amount = ",totalamt)
Q3.
def insure(x):
return 0.8*x
cost = int(input("Enter the replacement cost of a building "))
print("Minimum amount of insurance he or she should buy for the
property =",insure(cost))
Q4.
def monthly():
l = int(input("Monthly cost of loan payment "))
i = int(input("Monthly cost of insurance "))
g = int(input("Monthly cost of gas "))
o = int(input("Monthly cost of oil "))
t = int(input("Monthly cost of tires "))
m = int(input("Monthly cost of maintenance "))
total = l+i+g+o+t+m
return(total)
month = monthly()
def annual(x):
return 12*x
print("Total monthly cost =",month)
print("Total annual cost =", annual(month))
Q5.
x = int(input("Actual value of property "))
def assess(a):
return 0.6*a
def prop(a):
x = a/100
return(round(x*0.72,3))
print("Assessment Value = $",assess(x))
print("Property Tax = $",prop(assess(x)))
Q6.
fat = int(input("Enter the number of fat grams "))
carb = int(input("Enter the number of carbs grams "))
def calcfat(a):
return 9*a
def calccarb(a):
return 4*a
print("Calories from fat =",calcfat(fat))
print("Calories from carbs =",calccarb(carb))
print("Total calories intake =",calcfat(fat)+calccarb(carb))
Q7.
print("Enter number of tickets sold for each class :")
ca = int(input("Class A = "))
cb = int(input("Class B = "))
cc = int(input("Class C = "))
def a(a):
return 20*a
def b(a):
return 15*a
def c(a):
return 10*a
print("Total Income = $",a(ca)+b(cb)+c(cc))
Q8.
x = int(input("Enter the square feet of wall space to be painted
"))
y = int(input("Enter the price of the paint per gallon "))
def paint(a):
return round(x/112,2)
print("Gallons of paint required =",paint(x))
print("Hours of labour required =",paint(x)*8)
print("Cost of the paint = $",paint(x)*8*y)
print("Labour charges = $",paint(x)*8*35)
print("Total cost of the paint job = $",(paint(x)*8*y)+
(paint(x)*8*35))
Q9.
x = int(input("Enter the total sales for the month "))
def st(a):
return 0.05*a
def ct(a):
return 0.025*a
print("Amount of county sales tax =",ct(x))
print("Amount of state sales tax =",st(x))
print("Total sales tax (county plus state) =",ct(x)+st(x))
Q10.
def feet_to_inches(a):
return a*12
x = int(input("Enter the number of feet "))
print(feet_to_inches(x),"Inches")
Chapter 6
Q1.
t = open('num.txt', 'r')
text = t.read()
print(text)
t.close()
Q2.
x = input("Enter the file name ")
t = open(x,'r')
for i in range(5):
print(t.readline())
t.close()
Q3.
t = open('names.txt','r')
for i in range(15):
cont = t.readline()
print((1+i),":",cont)
t.close()
Q4.
name=open('names.txt','r')
count=0
for names in name:
ct=int(name)
count += 1
print('THE TOTAL NUMBER OF NAMES IN THE FILE IS:',count)
Q5.
number=open('numbers.txt','r')
count=0
for line in number:
ct=float(line)
count=count+ct
print(count)
number.close()
Q6.
number=open('numbers.txt','r')
count=0
total=0
for line in number:
ct=float(line)
total=total+ct
count=count+1
avg=total/count
print(avg)
number.close()
Q7.
file=open('files.txt','w')
count=0
num=int(input('ENETR THE MAXIMUM NUMBER OFSTORED RANDOM SERIES'))
for add in file:
y=int(input('ENTER A RANDOM NUMBER'))
if(y>=1 and y<=500):
file.write(y+'\n')
count += 1
if(count<num):
file.close()
Q8.
file=open('files.txt','w')
count=0
total=0
num=int(input('ENETR THE MAXIMUM NUMBER OFSTORED RANDOM SERIES'))
for add in file:
y=int(input('ENTER A RANDOM NUMBER'))
if(y>=1 and y<=500):
file.write(y+'\n')
print(y+'\n')
total=total+y
count += 1
if(count<num):
print('THE TOTAL RANDOM NUMBERS ARE:',count)
print('THE TOTAL OF RANDOM NUMBERS IS:',total)
file.close()
Q9.
try:
with open('tuition_data.txt', 'r') as file:
print("Year Tuition Amount")
print("---------------------")
except IOError:
print("Error: File not found or could not be opened")
Q10.
def inp():
Chapter 7
Q1.
week = []
for i in range(7):
week[i] = int(input("Enter the per day sale "))
total=0
for j in week:
total=total + j
print("Total sale for the week =",total)
Q2.
import random
lot = []
for i in range(7):
lot[i]=random.randint(0,9)
for i in range(7):
print(lot[i],end="")
Q3.
rain = []
for i in range(12):
rain[i] = int(input("Enter the total rainfall for each month
"))
total=0
for i in rain:
total = total+i
rain.sort()
print("Total rainfall for the year = ",total)
print("Average monthly rainfall = ",total/12)
print("Maximum rainfall = ",rain[11])
print("Minimum rainfall = ",rain[0])
Q4.
series = []
print("Enter a series of 20 numbers")
for i in range(20):
series[i] = int(input())
series.sort()
total=0
for i in series:
total+=i
print("lowest number =",series[0])
print("Highest number =",series[19])
print("Total =",total)
print("Average of the series =",total/20)
Q5.
t = open('charge_accounts.txt', 'r')
x = int(input("Enter the account number "))
account = t.readline()
flag=0
while(account!=''):
if(x == int(account)):
flag=1
break
account = t.readline()
if(flag==1):
print("Number is Valid")
else:
print("Number is invalid")
Q6.
list = [1,2,3,4,5,6,7,8,9,10]
n = int(input("Enter a number "))
for i in list:
if(i>n):
print(i,end=' ')
Q7.
correct = ['A', 'C', 'A', 'A', 'D', 'B', 'C', 'A', 'C', 'B', 'A',
'D', 'C', 'A', 'D', 'C', 'B', 'B', 'D', 'A']
student_anssheet = open('answersheet.txt', 'r')
student_answers = []
for line in student_anssheet:
student_answers.append(line.rstrip('\n'))
correct_ans = 0
incorrect_ans = 0
print("List of incorrect answers: ")
for i in range(20):
if student_answers[i] == correct[i]:
correct_ans += 1
else:
incorrect_ans += 1
print(str(i + 1))
print(" Total correct answers: ", correct_ans)
print(" Total incorrect answers: ", incorrect_ans)
if correct_ans >= 15:
print("The student has passed the examination")
else:
print("The student has failed the examination")
Q8.
boy = ""
girl = ""
try:
boy_names_file = open("BoyNames.txt", "r")
popular_boy_names = boy_names_file.readlines()
for i in range(len(popular_boy_names)):
popular_boy_names[i] = popular_boy_names[i].rstrip("\n")
girl_names_file = open("GirlNames.txt", "r")
popular_girl_names = girl_names_file.readlines()
for i in range(len(popular_girl_names)):
popular_girl_names[i] = popular_girl_names[i].rstrip("\
n")
if boy == "X":
print("Skipping boy names")
elif boy in popular_boy_names:
print(f"{boy} is one of the most popular boy's names.")
else:
print(f"{boy} is not one of the most popular boy's
names.")
if girl == "X":
print("Skipping girl names")
elif girl in popular_girl_names:
print(f"{girl} is one of the most popular girl's names.")
else:
print(f"{girl} is not one of the most popular girl's
names.")
except IOError:
print("The file could not be found or read")
except IndexError:
print("There was an indexing error")
except:
print("There was an error")
Q9.
def read_population(file_name):
try:
with open(file_name, 'r') as file:
population_data = [int(line.strip()) for line in
file.readlines()]
return population_data
except FileNotFoundError:
print(f"File '{file_name}' not found.")
return []
def calculate_average_change(population_data):
changes = [population_data[i + 1] - population_data[i] for i
in range(len(population_data) - 1)]
average_change = sum(changes) / len(changes)
return average_change
def year_with_greatest_increase(population_data):
changes = [population_data[i + 1] - population_data[i] for i
in range(len(population_data) - 1)]
max_increase_year = changes.index(max(changes)) + 1951
return max_increase_year
def year_with_smallest_increase(population_data):
changes = [population_data[i + 1] - population_data[i] for i
in range(len(population_data) - 1)]
min_increase_year = changes.index(min(changes)) + 1951
return min_increase_year
def main():
file_name = "USPopulation.txt"
population_data = read_population(file_name)
if not population_data:
print("Failed to read population data. Exiting program.")
return
average_change = calculate_average_change(population_data)
greatest_increase_year =
year_with_greatest_increase(population_data)
smallest_increase_year =
year_with_smallest_increase(population_data)
if __name__ == "__main__":
main()
Q10.
def read_world_series_data(file_name):
with open(file_name, 'r') as file:
data = file.readlines()
data = [team.strip() for team in data]
return data
def main():
file_name = "world_series_winners.txt"
world_series_data = read_world_series_data(file_name)
team_name = input("Enter the name of a team: ")
wins = count_wins(team_name, world_series_data)
Chapter 8
Q1.
x = input("Enter the name")
for i in x:
if i>='A' and i<='Z':
print(i,end='.')
Q2.
x = input("Enter the string")
total=0
for i in x:
total+=int(i)
print(total)
Q3.
date = input("Enter the Date ")
mon = date[2:4]
if(mon=='01'):
mon='January'
elif(mon=='02'):
mon = 'Feburary'
elif(mon=='03'):
mon = 'March'
elif(mon=='04'):
mon = 'April'
elif(mon=='05'):
mon = 'May'
elif(mon=='06'):
mon = 'June'
elif(mon=='07'):
mon = 'July'
elif(mon=='08'):
mon = 'August'
elif(mon=='09'):
mon = 'September'
elif(mon=='10'):
mon = 'October'
elif(mon=='11'):
mon = 'November'
elif(mon=='12'):
mon = 'December'
else:
print("Wrong input")
print(mon,date[0:2]+','+date[4:8])
Q4.
x = input("Enter the string ")
x = x.upper()
for i in x:
match i:
case " ":
print(" ", end='')
case ",":
print("--..--", end='')
case ".":
print(".-.-.-", end='')
case "?":
print("..--..", end='')
case "0":
print("-----", end='')
case "1":
print(".----", end='')
case "2":
print("..---", end='')
case "3":
print("...--", end='')
case "4":
print("....-", end='')
case "5":
print(".....", end='')
case "6":
print("-....", end='')
case "7":
print("--...", end='')
case "8":
print("---..", end='')
case "9":
print("----.", end='')
case "A":
print(".-", end='')
case "B":
print("-...", end='')
case "C":
print("-.-.", end='')
case "D":
print("-..", end='')
case "E":
print(".", end='')
case "F":
print("..-.", end='')
case "G":
print("--.", end='')
case "H":
print("....", end='')
case "I":
print("..", end='')
case "J":
print(".---", end='')
case "K":
print("-.-", end='')
case "L":
print(".-..", end='')
case "M":
print("--", end='')
case "N":
print("-.", end='')
case "O":
print("---", end='')
case "P":
print(".--.", end='')
case "Q":
print("--.-", end='')
case "R":
print(".-.", end='')
case "S":
print("...", end='')
case "T":
print("-", end='')
case "U":
print("..-", end='')
case "V":
print("...-", end='')
case "W":
print(".--", end='')
case "X":
print("-..-", end='')
case "Y":
print("-.-", end='')
case "Z":
print("--..", end='')
Q5.
x = input("Enter the number ")
x = x.upper()
for i in x:
if i>='A' and i<='C':
print('2', end='')
elif i>='D' and i<='F':
print('3', end='')
elif i>='G' and i<='I':
print('4', end='')
elif i>='J' and i<='L':
print('5', end='')
elif i>='M' and i<='O':
print('6', end='')
elif i>='P' and i<='S':
print('7', end='')
elif i>='T' and i<='V':
print('8', end='')
elif i>='W' and i<='Z':
print('9', end='')
else:
print(i, end='')
Q6.
x = open('text.txt', 'r')
line = x.readline()
line = line.rstrip('\n')
no=0
words=0
while(line != ''):
line = line + ' '
for i in line:
if(i==' '):
words+=1
no+=1
line=x.readline()
line = line.rstrip('\n')
x.close()
print("Average no of words per sentence =",int(words/no))
Q7.
t = open('text.txt','r')
text = t.read()
count_uppercase=0
count_lowercase=0
count_digit=0
count_whitespace=0
for i in text:
if(i.isupper()==1):
count_uppercase=count_uppercase+1
if(i.islower()==1):
count_lowercase=count_lowercase+1
if(i.isspace()==1):
count_whitespace=count_whitespace+1
if(i.isdigit()==1):
count_digit=count_digit+1
print('The number of uppercase letters in the
file :',count_uppercase)
print('The number of lowercase letters in the
file:',count_lowercase)
print('The number of digits in the file :',count_digit)
print('The number of whitespace characters in the
file :',count_uppercase)
Q8.
def capitalizer(st1):
st2=''
l = len(st1)
cap = 0
for i in range(l):
if (st1[i]=='.' or st1[i]=='?'):
st2=st2+st1[i]
cap = i+2
elif(i==cap):
st2=st2+st1[i].upper()
else:
st2=st2+st1[i]
return st2
def main():
str = input("Enter the string ")
print(capitalizer(str))
main()
Q9.
def vowels(st1):
st1 = st1.upper()
count=0
for i in st1:
if(i=='A' or i=='E' or i=='I' or i=='O' or i =='U'):
count+=1
return count
def consonants(st1):
st1 = st1.upper()
count=0
for i in st1:
if(i!='A' and i!='E' and i!='I' and i!='O' and i!='U' and
i !=' '):
count+=1
return count
def main():
str = input("Enter the string ")
print("Vowels =",vowels(str))
print("Consonants =", consonants(str))
main()
Q10.
def freq(st1):
st1 = st1.upper()
max=0
most = ''
for i in st1:
count=0
for j in st1:
if(i==j):
count+=1
if (count>max):
max = count
most =i
count=0
return most
def main():
str = input("Enter the string ")
print(freq(str))
main()