[go: up one dir, main page]

0% found this document useful (0 votes)
12 views5 pages

Cs Record 2

The document contains a Python code to create a function that displays country, capital and currency details in a tabular format by taking user input and storing it in a dictionary. It also allows the user to search for a country and displays its capital and currency. The code contains another Python program that opens a text file, counts the occurrences of words "is" and "the" in the file and displays the counts. It also counts the number of lines starting with character 'A'. The code shows another Python program that reads from a text file, splits the lines into two new files based on whether the line contains the letter 'a' or not. It

Uploaded by

Sakshi Mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

Cs Record 2

The document contains a Python code to create a function that displays country, capital and currency details in a tabular format by taking user input and storing it in a dictionary. It also allows the user to search for a country and displays its capital and currency. The code contains another Python program that opens a text file, counts the occurrences of words "is" and "the" in the file and displays the counts. It also counts the number of lines starting with character 'A'. The code shows another Python program that reads from a text file, splits the lines into two new files based on whether the line contains the letter 'a' or not. It

Uploaded by

Sakshi Mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

S.

Krish Hariharan 12114


CODE:
#functions
def cont(con):
print("In tabular form:")
print("COUNTRY","\t\t","CAPITAL","\t\t","CURRENCY")
for i in con:
print(i,"\t\t",con[i][0],"\t\t",con[i][1])
print()
name=input("Enter the country's name that you want to know about:")
if name in con:
print("The capital of",name,"is",con[name][0],"and currency is",con[name][1])
else:
print("The country is not in the list!!")
#main program
print("PROGRAM THAT SHOWS COUNTRY, CAPITAL AND CURRENCY
DETAILS IN TABULAR FORM")
n=int(input("Enter the number of countries that you want to add:"))
con={}
for i in range(n):
country=input("Enter your country name:")
cap=input("Enter the capital:")
cur=input("Enter the currency:")
con[country]=cap,cur
cont(con)
OUTPUT:

PROGRAM THAT SHOWS COUNTRY, CAPITAL AND CURRENCY DETAILS IN


TABULAR FORM
Enter the number of countries that you want to add:4
Enter your country name:Spain
Enter the capital:Madrid
Enter the currency:Euro
Enter your country name:Japan
Enter the capital:Tokyo
Enter the currency:Yuan
Enter your country name:China
Enter the capital:Beijing
Enter the currency:Yen
Enter your country name:Cuba
Enter the capital:Havana
Enter the currency:Peso
In tabular form:
COUNTRY CAPITAL CURRENCY
Spain Madrid Euro
Japan Tokyo Yuan
China Beijing Yen
Cuba Havana Peso

Enter the country's name that you want to know about:Spain


The capital of Spain is Madrid and currency is Euro
S. Krish Hariharan 12114
CODE:
#functions
a=b=0
f=open('text.txt','r')
strng=f.read()
l=strng.split()
for i in l:
if i.lower()=="is":
a+=1
elif i.lower()=="the":
b+=1
print("The count of 'is' is",a)
print("The count of 'the' is",b)
f.close()
print()
f=open('text.txt','r')
stng=f.readline()
count=0
for i in strng:
if i[0]=='A':
count+=1
print("The lines starting with A is",count)
f.close()

INPUT: (text.txt)
A boy is playing there.
There is a playground.
An aeroplane is in the sky.
Alphabets and numbers are allowed in password.
Computer science is easy to learn
Python programming skills is very useful for us.
The united states is one of the largest country

OUTPUT:
The count of 'is' is 6
The count of 'the' is 3

The lines starting with A is 3


S. Krish Hariharan 12114
CODE:
f=open('AI.txt','r')
s=f.readlines()
f.close()
f1=open('AI_1.txt','w')
f2=open('AI_2.txt','w')
for line in s:
if "a" in line:
f1.write(line)
else:
f2.write(line)
f1.close()
f2.close()

INPUT: AI.txt :
AI refers to artificial intelligence
it is the intelligence of machines
with AI machines can perform reasoning and problem solving
AI is the simulation of human intelligence by machines
it is the development in the world technology

OUTPUT:

AI_1.txt :
AI refers to artificial intelligence
it is the intelligence of machines
with AI machines can perform reasoning and problem solving
AI is the simulation of human intelligence by machines

AI_2.txt:
it is the development in the world technology
S. Krish Hariharan 12114
CODE:
f=open("story.txt",'r')
s=f.read()
v=c=u=l=o=0
for i in s:
if i.isalpha():
if i.isupper():
u+=1
if i.islower():
l+=1
if i in "AEIOUaeiou":
v+=1
if i not in "AEIOUaeiou":
c+=1
else:
if i.isspace():
pass
else:
o+=1
print("Vowel count:",v)
print("consonants count:",c)
print("uppercase count:",u)
print("Lowercase count",l)
print("other characters count:",o)
f.close()

INPUT: “story.txt”
Ram lives in #23, NEHRU nagar, New Delhi-400 034. his house is near our school.

OUTPUT:
Vowel count: 22
consonants count: 29
uppercase count: 8
Lowercase count 43
other characters count: 14

You might also like