- UserDefinedFunction
- whileloop
- forloop
- List
- OOPS
- Dictionary
- Lambda Funtion
- List Comprehension
- MFR Function
- File Handling
- Task Given
{{FLoutput}}
Output : {{list_q1_result | json}}
Q2. Enter index number and element from user to insert number to the specified index in the list.Output : {{list_q2_result}}
Q3.Create another list of five numbers and append all the numbers from list 2 to list one.Output : {{list_q3_result}}
Q4. Display list with the step value two.Output : {{list_q4_result}}
Q5. Display middle three element of list.Output : {{list_q5_result}}
Output : {{oops_q1_result}}
Q1(a). Create Dictionary of five person with data items within
nested values we have name, age, birthdate.
Name :
Age :
Birthdate :
{{dictOutputq1}}
Question 1 Python Code :
- var a = {
“p1”: {"Name": "Asf", "Age": 23, "Birthdate": "14/08/2000"},
"P2": {"Name": "Kulsum", "Age": 18, "Birthday”: “05/10/2005"},
"P3": {"Name": "Yusuf", "Age"; 22, "Birthdate": "06/07/2001"},
"P4": {"Name": “Amina", "Age": 14, "Birthdate": "16/12/2009"},
"P5": {"Name": "Kulsum", "Age": 18, “Birthdate": "05/10/2005"}
}
print (a)
Python Output:
{
“p1”: {"Name": "Asf", "Age": 23, "Birthdate": "14/06/2000"},
"P2": {"Name": "Kulsum", "Age": 18, "Birthday”: “05/10/2005"},
"P3": {"Name": "Yusuf", "Age"; 22, "Birthdate": "06/07/2001"},
"P4": {"Name": “Amina", "Age": 14, "Birthdate": "16/12/2009"},
"P5": {"Name": "Kulsum", "Age": 18, “Birthdate": "05/10/2005"}
}
(b)Display all the keys of person dictionary.
{{dictOutputq2}}
Python Code :
-print (var, keys ())
python Output:
dict_keys ([‘P1','P₂', 'P3', 'P4', 'PS'])
(c) Display name of person 3.
{{dictOutputq3}}
Python code :
→ print (var. get ("p3"))
output: {"Name": "Yusuf" "Age: 22, "Birthdate": “14/06/2001”
(d) Display all the values of person Dictionary.
-print (var. values ())
Output:
dict_values = ([
{"Name": "Asf", "Age": 23, "Birthdate": "14/06/2000"},
{"Name": "Kulsum", "Age": 18, "Birthday”: “05/10/2005"},
{"Name": "Yusuf", "Age"; 22, "Birthdate": "06/07/2001"},
{"Name": “Amina", "Age": 14, "Birthdate": "16/12/2009"},
{"Name": "Kulsum", "Age": 18, “Birthdate": "05/10/2005"}
]}
(e) Add Sixth person in dictionary.
a· update (a2)
print (a)
Output:
{
“p1”: {"Name": "Asf", "Age": 23, "Birthdate": "14/06/2000"},
"P2": {"Name": "Kulsum", "Age": 18, "Birthday”: “05/10/2005"},
"P3": {"Name": "Yusuf", "Age"; 22, "Birthdate": "06/07/2001"},
"P4": {"Name": “Amina", "Age": 14, "Birthdate": "16/12/2009"},
"P5": {"Name": "Kulsum", "Age": 18, “Birthdate": "05/10/2005"},
"P6": {"Name": "Afsari Khan", "Age" 34", Birthdate" = "1/01/1979"}
(f). Change the name Person2(pushyal).
-a ["p2"] ["Name"] = "Pushyal"
print (var)
pdf
Q1. Create Lambda function to find out power of passed number.
→ import math.
power = lambda a: Math.issqrt (a)
print ("Power of Entered Number is: ", power (110))
output:
Power of entered number is 10.
Q2. Create lambda function with two parameters to find power of
the number where 2nd number is power of first.
-import math
power = lambda a, b: a**b
print (power (a = (2), b = (3)]
Output: 8
Q3. Create lambda function to find out entered no is positive negative.
{{lambdaoutputq3}}
- num = lambda a: “Positive” is a is greater than 0 else “Negative”.
print (num (-1)
Q4. Create lambda find out to find out biggest between two number.
{{lambdaoutputq4}}
- num = lambda a, b: “A is big” if a greater than b else “B is big”
Q5. Create lambda find out to find out entered number is even or odd.
{{lambdaoutputq5}}
- num = lambda a: "Even" if a % 12 == 0 else "Old Number")
print (num(3)
Output: odd number
Q6. Create lambda function to find Cube of a number.
Output : {{lambdaoutputq6}}
- num = lambda a: a***
print (num (3))
Output:27
Q7. Create lambda function to find out eligibility of age.
Output: {{lambaOutput}}
python output : {{lambaOutputExplain}}
Q1. Using list Comprehension find out Number Divisible by 7 from 1 to 1000?
python code :
- xyz = [a for a in range (7, 1001) if a % 7 == 0]
print(xyz)
Q2. Count Number of Spaces in string (using List Comprehension)?
python code :
- strg = "kjdldmm skdjlmld kldllmkk;l nlmld kdllmdm kdjdmmd mlkmm mlm;m jlkf jmklmf "
xyz = [a for a in strg if a.count(" ") ]
print("Number of spaces in string : ",xyz.__len__())
output : Number of spaces in string : 11
Q3. Using List Comprehension Convert all Character to upper case in list Of words?
strg1 = "kjdldmm skdjlmld kldllmkk;l nlmld kdllmdm kdjdmmd mlkmm mlm;m jlkf jmklmf "
abc = [a.upper() for a in strg1 ]
print("Capital Strings : ","".join(abc))
output: Capital Strings : KJDLDMM SKDJLMLD KLDLLMKK;L NLMLD KDLLMDM KDJDMMD MLKMM MLM;M JLKF JMKLMF
Q4. Using list Comprehension find out Common Number in between two list?
ls = [12,2,1,43,5,3]
ls2 = [2,5,8,9,43,76,1]
liscompre = [a for a in ls if a in ls2]
print(liscompre)
output : [2, 1, 43, 5]
Q5. Using List Comprehension find all Number from 12 to 1000 that has 3 in them?
[13, 23, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 53, 63, 73, 83, 93, 103, 113, 123, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 143, 153, 163, 173, 183, 193, 203, 213, 223, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 243, 253, 263, 273, 283, 293, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392,
393, 394, 395, 396, 397, 398, 399, 403, 413, 423, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 443, 453, 463, 473, 483, 493, 503, 513, 523, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 543, 553, 563, 573, 583, 593, 603, 613, 623, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 643, 653, 663, 673, 683, 693, 703, 713, 723, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 743, 753, 763, 773, 783, 793, 803, 813, 823, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 843, 853, 863, 873, 883, 893, 903, 913, 923, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 943, 953, 963, 973, 983, 993]
Dictionary comprehension
# normal
ls = [12,2,1,43,5,3]
ls2 = [2,5,8,9,43,76,1]
xyz = {x:y for (x,y) in zip(ls,ls2)}
print(xyz)
output: {12: 2, 2: 5, 1: 8, 43: 9, 5: 43, 3: 76}
# Nested
kii = ["p1","p2","p3","p4","p5","p6"]
ls = ["Aseef","Shubham","Ali","Ram","Sai","Shiva"]
ls2 = [2,5,8,9,43,76,1]
xyz = {x:{y:z} for (x,y,z) in zip(kii,ls,ls2)}
print(xyz)
output: {'p1': {'Aseef': 2}, 'p2': {'Shubham': 5}, 'p3': {'Ali': 8}, 'p4': {'Ram': 9}, 'p5': {'Sai': 43}, 'p6': {'Shiva': 76}}
Q1. Using Het map function create two power list where is power of 2nd.
- from math import *
Ls = [4,9,16, 25,36]
asf = map(lambda a: math.sqrt(a), ls)
print (list (asf))
output: [2,3,4,5,6]
Q2. Create list of numbers using map find out even or odd numbers (using lambda).
- wc = [2,4S, 37, 38, 100]
asf = map ((lambda a: str (a) + “is Even Number" if a%2 == 0 else
str(a) + " is Odd Number ", wc)
print(list(asf))
Q 1. using filter find out even numbers in loop (use lambda)
- ab = [12,33,4 4, 3, 2, 43, 65, 867, 908]
filter (lambda a: 1 if a %2== 0 else 0 ab)
print (list (ls))
Q2. Using filter find all find all fruits in list Starting with A (use Lambda)
- ab = ["Guava", "Mango" "Banana", "Pomegranates", ”Chiku”, "Lichi"]
Ls = filter (lambda a : 1 if “e” in a else o, ab).
print (list ((s))
Q1. Using reduce find out biggest between two numbers in list (uses lambda)
-from functools import reduce.
- ab = [13,2]
Is = reduce (lambda a,b: "A is Big" if a greater than b else "B is Big", ab)
Print(ls).
Q2 find out smallest number in list using reduce.
- def asf(a, b):
ls = [a,b]
return min (ls)
ak =[12, 14, 1, 56,77]
redu = reduce (asf, ac)
print (redu)
Q3. Using reduce find out palindrome strings (use lambda).
→ This question is removed by faculty
Q. Allow the user to write in file.txt and if user type exit file should
get close.
- abc = input ("Do you want to write in the file? (YES/NO)")
b = ["end", "END"]
While abc == “yes” or abc == "YES":
file = open ("file.txt", "w")
asf = 1
while asf less than=5: xyz=input (" ")
file.write(xyz)
for C in xyz:
for d in b:
if c in b:
file.close()
asf = 6
asf =+ 1
Print (“\t*** Quiz Game ***”)
print ("\t *** Your Answer in small letter hint → (a, b, c, d)
****")
11 = [
"1. What is the colour of a lemon? ",
"2. What is the full form of pf”,
“3. Who is the Owner of WIPRO Company?”,
"4. Among Below which is the biggest Continent in the world?",
"5. Which is the largest animal in the world.?”,
“6. Which is the 29th State of India?”,
“7. Which continent is known as Dark Continent?",
"8. Which is the largest desert in the world?",
"9. How many letters are there in the English alphabet?"
“10. How many days are there August?"
]
l2 = ["Red" "Blue", "Green", “Yellow”],
[“Prefer Fortune", "Policy further”, “Provident Fund",
"Professor Folly"],
[“Azim Premji”, “Anand Mahindra”,
Ravi Teja", "Aseef khan, Walmart John"],
["Africa" "Asia"," Russia"," "Antarctica"],
[“Giraffe”, “Elephant”, "Gorilla", "Whale”],
["Rajasthan", "Goa", "Uttarakhand”, “Telangana”],
[“America” "Green Land", "Switzerland", "Australia"],
[“jezail”, “Egyptian” "Arab" "Sahara”],
["27", "21", "23", "26"],
["28","29","30", “31”]
l3 = ["d", "c", "a", "b", "d", "d", "d", "d", "d”]
Count = 1
for a in zip (l1, l2): ← (Very Imp function)
print(a)
user = input ("Answer: ")
if user in L3:
Count += 1
if count == l3:
if count! = 10:
print (" Your Score: ", count)
elif count! = 10:
print (" Not bad you Scored!", count)
else:
print ("OOPS You failed!")
abc = input("Start Game Yes/No?")
lst = []
while abc == "Yes":
user = input("Enter Text : ")
part = user.split(' ')
if part:
if part[0]:
pass
if len(part) greater than 1 and part[1]=="exit":
break
Click on the computer, phone or the cup of tea to go new page and read more topic:
Boriwali(West)
We enable people across the globe to use I.T. optimally and efficiently through world-class I.T. training solutions. Today, Aptech students are working all over the world building knowledge corporations, communities and knowledge societies.
Output is correct Add your key
Assignment Using Array to Insert and Display Value
Exiting Element in Array: [10,20]
Example of 1D and 2D Array
Assignment Given Aptech faculty: Mrs.Supriya Kulkarni
Assignment Given Aptech faculty: Mrs.Supriya Kulkarni
Example