-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpro4.py
More file actions
65 lines (59 loc) · 1.63 KB
/
Copy pathpro4.py
File metadata and controls
65 lines (59 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
List=
A list is a collection of items,Mutable (you can change it),Defined using []
append(x) Adds item at end,insert(i, x) Adds item at index,
extend(iterable) Adds multiple items,remove(x) Removes specific value
pop(i) Removes item at index,clear() Removes all elements
index(x) Returns index of value,count(x) Counts occurrences
sort() Sorts list,reverse() Reverses list,copy() Returns copy of list
A tuple is also a collection of items
Immutable (cannot be changed)
Defined using parentheses ()
count(x) Counts occurrences,index(x) Finds index of value
"""
# 1>to store four frits as input in list
Fruits=[]
f1=input("enter your fruit")
(Fruits.append(f1))
f2=input("enter your fruit")
(Fruits.append(f2))
f3=input("enter your fruit")
(Fruits.append(f3))
f4=input("enter your fruit")
(Fruits.append(f4))
print(Fruits)
# 2>wap to accept mark of 4 stu and sorten them
marks=[]
stu1=int(input("enter your marks:",))
marks.append(stu1)
stu2=int(input("enter your marks:",))
marks.append(stu2)
stu3=int(input("enter your marks:",))
marks.append(stu3)
stu4=int(input("enter your marks:",))
marks.append(stu4)
print("Before sorting:", marks)
print(marks)
marks.sort()
print("After sorting:", marks)
print(type(marks))
# 3>write a immutable tuple
a=("harry","nikhil",1,4)
a[2]="ball"
print(a)
# 4>wap list of 4 number sum
a=[]
f1=int(input("enter your number: "))
a.append(f1)
f2=int(input("enter your number: "))
a.append(f2)
f3=int(input("enter your number: "))
a.append(f3)
f4=int(input("enter your number: "))
a.append(f4)
print(a)
print("the sum of numbers are:",sum(a))
# 5> WAP to count the number of zero in there
a=(7,0,8,0,0,9)
b=a.count(0)
print(b)