Professional Documents
Culture Documents
Problem 1
Write a program to count the characters, words and lines from a text file
Program :
#variable declaration
line=0
char=0
word=1
#opening file and read a file
with open('C:/Users/rrt11/Desktop/linux.txt','r')as file:
Output:
Write a program to capitalize the first letter of each word in a text file
Program:
#opening file and read a file
with open('C:/Users/rrt11/Desktop/linux.txt','r')as file:
#reading every line in file
for line in file:
print(line.title())
#title() function can be used for capitalize for everyword
Output:
Operating System Is A Software Which Operates All Hardware Compnentes.
Os Is Interface Between And A Computer Is Called Operating System
Memory Management
File Management
Security
Disk Management
Job Scheduling
Device Driver
I/O Operations
Kernal:-One Kernal And Shell
Kernal Is A Part Of The Inbuilt In Os Whatever The Command User Gives The Kernal And
Kernal Gives The Hardware
Problem 3
Program
Output:
enter a number :- 345
['3']
['4']
['5']
Problem 4
Program :
Output:
Program:
#Take a input from user
word=(input("Enter your Number :- "))
#Reversing a integer
print("The reverse of number is :-",word[::-1])
Output:
Enter your Number :- 768
The reverse of number is :- 867
Problem 6
Write a program to login to a database and export table content to a file in CSV
format
Program:
#Import statements
import csv
import mysql.connector
mydb = mysql.connector.connect(
#Connecting to database
host="localhost",
user="root",
passwd="rrt@11",
database="rrtintranet"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM rrtintranet.new_table")
myresult = mycursor.fetchall()
for x in myresult:
print(x)
#Opening a file
with open('C:/Users/rrt11/Desktop/king27.csv', 'a') as csvFile:
writer = csv.writer(csvFile)
#Writing data into file
writer.writerow(x)
Output:
jagan,ck palli,programmer
kavya,Anantapur,Frontend
Nandhakishore,Malayanur,Backend
Raghu ,Anantapur,Bigdata
Problem 7
Program:
#Taking a input form user
number = int(input("Enter any decimal number: "))
print("Equivalent Binary Number: ", bin(number))
#Taking a String from user
string=input("Enter a string:")
encode=' '.join(format(ord(x), 'b') for x in string)
print(encode)
Output: