Commit 094c6bda authored by kranthi.kumar's avatar kranthi.kumar

Basic commit

parent 83f7d40b
from scripts.core.sample import Use_case
use_case_object = Use_case()
# take input from user
choice = int(input("Please Enter the Use Case number :"))
if choice == 1:
use_case_object.use_case1()
elif choice == 2:
use_case_object.use_case2()
elif choice == 3:
use_case_object.use_case3()
elif choice == 4:
use_case_object.use_case4()
elif choice == 5:
use_case_object.use_case5()
elif choice == 6:
use_case_object.use_case6()
else:
print("Invalid input")
Name,population,Rank
Andhra Pradesh,"49,386,799",7
Uttar Pradesh," 199,812,341",4
Maharashta,"112,372,972",3
Bihar," 103,804,637",12
West Bengal,"91,347,736",13
Madhya Pradesh,"72,597,565",2
Tamil Nadu,"72,138,958",10
Rajasthan,"68,621,012",1
Karnataka,"61,130,704",6
Gujarat,"60,383,628",5
Odisha,"41,947,358",8
Telangana,"35,286,757",11
Kerala,"3,387,677",21
Jharkhand," 32,966,238",15
Assam,"31,169,272",16
Punjab,"27,704,236",19
Chattisgarh,"25,540,196",9
Haryana,"25,353,081",20
Jammu and Kashmir,"12,548,926",UT6
Uttarakhand,"10,116,752",18
Himachal Pradesh,"6,864,602",17
Tripura,"3,671,032",26
Meghalaya,"2,964,007",22
Manipur,"2,721,756",23
Nagaland,"1,980,602",25
Goa,"1,457,723",28
Arunachal Pradesh,"1,382,611",14
Mizoram,"1,091,014",24
Sikkim,"607,688",27
Andhra Pradesh,Arunachal Pradesh,Assam,Bihar,Chhattisgarh,Goa,Gujarat,Haryana,Himachal Pradesh,Jharkhand,Karnataka,Kerala,Madhya Pradesh,Maharashtra,Manipur,Meghalaya,Mizoram,Nagaland,Odisha,Punjab,Rajasthan,Sikkim,Tamil Nadu,Telangana,Tripura,Uttarakhand,Uttar Pradesh,West Bengal,
\ No newline at end of file
import csv
class Use_case:
# use case 1
@staticmethod
def use_case1():
# creating a list
list_data = ["Kranthi", "Kumar", "chowdary"]
# Iterating the List
for value in list_data:
# Printing the values in List
print(value)
# use case 2
@staticmethod
def use_case2():
# creating a tuple to store state of india'
tuple_data = (
"Andhra Pradesh", "Arunachal Pradesh", "Assam,Bihar", "Chhattisgarh", "Goa", "Gujarat", "Haryana",
"Himachal Pradesh",
"Jharkhand", "Karnataka", "Kerala", "Madhya Pradesh", "Maharashtra", "Manipur", "Meghalaya", "Mizoram",
"Nagaland",
"Odisha", "Punjab", "Rajasthan", "Sikkim", "Tamil Nadu", "Telangana", "Tripura", "Uttarakhand",
"Uttar Pradesh",
"West Bengal")
# Iterating the tuple
for value in tuple_data:
# Printing the values in tuple
print(value)
# use case 3
@staticmethod
def use_case3():
# creating a list
list_data = ["Andhra Pradesh,", "Arunachal Pradesh,", "Assam,", "Bihar,", "Chhattisgarh,", "Goa,", "Gujarat,",
"Haryana,", "Himachal Pradesh,", "Jharkhand,", "Karnataka,", "Kerala,", "Madhya Pradesh,",
"Maharashtra,",
"Manipur,", "Meghalaya,", "Mizoram,", "Nagaland,", "Odisha,", "Punjab,", "Rajasthan,", "Sikkim,",
"Tamil Nadu,", "Telangana,", "Tripura,", "Uttarakhand,", "Uttar Pradesh,", "West Bengal,"]
# opening the file as write mode
with open("input.txt", 'w') as writer:
for value in list_data:
# storing the values into file
writer.write(value)
# use case 4
@staticmethod
def use_case4():
# opening the file as read mode
with open("input.txt", 'r') as reader:
# reading the data from file
data_required = reader.read().split(",")
for value in data_required:
# printing the values in list
print(value)
# use case 5
@staticmethod
def use_case5():
# creating collocation
colloction_data = [{"Name": "Andhra Pradesh", "population": "49,386,799", "Rank": "7"},
{"Name": "Uttar Pradesh", "population": " 199,812,341", "Rank": "4"},
{"Name": "Maharashta", "population": "112,372,972", "Rank": "3"},
{"Name": "Bihar", "population": " 103,804,637", "Rank": "12"},
{"Name": "West Bengal", "population": "91,347,736", "Rank": "13"},
{"Name": "Madhya Pradesh", "population": "72,597,565", "Rank": "2"},
{"Name": "Tamil Nadu", "population": "72,138,958", "Rank": "10"},
{"Name": "Rajasthan", "population": "68,621,012", "Rank": "1"},
{"Name": "Karnataka", "population": "61,130,704", "Rank": "6"},
{"Name": "Gujarat", "population": "60,383,628", "Rank": "5"},
{"Name": "Odisha", "population": "41,947,358", "Rank": "8"},
{"Name": "Telangana", "population": "35,286,757", "Rank": "11"},
{"Name": "Kerala", "population": "3,387,677", "Rank": "21"},
{"Name": "Jharkhand", "population": " 32,966,238", "Rank": "15"},
{"Name": "Assam", "population": "31,169,272", "Rank": "16"},
{"Name": "Punjab", "population": "27,704,236", "Rank": "19"},
{"Name": "Chattisgarh", "population": "25,540,196", "Rank": "9"},
{"Name": "Haryana", "population": "25,353,081", "Rank": "20"},
{"Name": "Jammu and Kashmir", "population": "12,548,926", "Rank": "UT6"},
{"Name": "Uttarakhand", "population": "10,116,752", "Rank": "18"},
{"Name": "Himachal Pradesh", "population": "6,864,602", "Rank": "17"},
{"Name": "Tripura", "population": "3,671,032", "Rank": "26"},
{"Name": "Meghalaya", "population": "2,964,007", "Rank": "22"},
{"Name": "Manipur", "population": "2,721,756", "Rank": "23"},
{"Name": "Nagaland", "population": "1,980,602", "Rank": "25"},
{"Name": "Goa", "population": "1,457,723", "Rank": "28"},
{"Name": "Arunachal Pradesh", "population": "1,382,611", "Rank": "14"},
{"Name": "Mizoram", "population": "1,091,014", "Rank": "24"},
{"Name": "Sikkim", "population": "607,688", "Rank": "27"},
]
# Iterating the Collocation
for value in colloction_data:
# Printing the values in Collocation
print("Name Of Stae :", value["Name"], " Population is :", value["population"], " Rank is :",
value["Rank"])
# opening Csv file
with open('input.csv', 'w') as csvfile:
fieldnames = ['Name', 'population', 'Rank']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
# Iterating the Collocation
for value in colloction_data:
# writeing data into the file
writer.writerow(value)
# use case 6
@staticmethod
def use_case6():
# define functions
# Function for Adding two numbers
def add(x, y):
return x + y
# Function for subtract two numbers
def subtract(x, y):
return x - y
# Function for multiply two numbers
def multiply(x, y):
return x * y
# Function for divide two numbers
def divide(x, y):
return x / y
# take input from the user
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
choice = input("Enter choice(1/2/3/4):")
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
if choice == '1':
print(num1, "+", num2, "=", add(num1, num2))
elif choice == '2':
print(num1, "-", num2, "=", subtract(num1, num2))
elif choice == '3':
print(num1, "*", num2, "=", multiply(num1, num2))
elif choice == '4':
print(num1, "/", num2, "=", divide(num1, num2))
else:
print("Invalid input")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment