-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchap 12_19.py
133 lines (97 loc) · 2.5 KB
/
chap 12_19.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Chapter 12-19 & assignment 2
# And and or operator
if 4 > 2 and 5 > 4:
print("and contdition true")
if 'hello' == 'hello' and 'world' == 'abc':
print("and contdition false")
if 9 < 7 or "talha" == "talha":
print("or condition true")
if 9 < 7 or "hello" == "world":
print("or condition false")
# if statment nested
if 1 == 1:
if 2 != 2:
print("nested if")
elif 'abc' == 'abc':
print('nested elif')
else:
print("nested else")
else:
print('else nested')
# single line comment using "#"
# multi line comment using " ''' "
'''
my name
is talha
multiple line comment
'''
# List in python aka array
numbers = [6, 5, 4, 3, 2, 1]
print(numbers)
print(numbers[4])
print(numbers.__len__())
# using append push in js
numbers.append(45)
print(numbers)
numbers.pop()
print(numbers)
numbers.insert(3, 99)
print(numbers)
# slice in python
num = [11, 12, 13, 14, 15, 16]
newArray = num[2:5] # print index 2 to 5
print(newArray)
del num[0]
print(num)
num.remove(12) # delete using value
print(num.pop()) # print last value
# Assignment no: 2 & 3
# Marksheet
print("Marks of Five Subjects")
sub1=int(input("Enter marks of English: "))
sub2=int(input("Enter marks of Math: "))
sub3=int(input("Enter marks of Science: "))
sub4=int(input("Enter marks of Urdu: "))
sub5=int(input("Enter marks of Islamiat: "))
tmarks=sub1 + sub2 + sub3 + sub4 + sub4
print("Total marks" , tmarks , 'out of 500')
percentage= tmarks / 500 * 100
print(percentage , '%')
if(percentage >= 90 and percentage <= 100):
print("Grade: A+")
elif(percentage >= 80 and percentage < 90):
print("Grade: A")
elif(percentage >= 70 and percentage < 80):
print("Grade: B")
elif(percentage >= 60 and percentage < 70):
print("Grade: C")
elif(percentage >= 50 and percentage < 60):
print("Grade: D")
else:
print("Fail")
# calculator
val1 = int(input('Enter First Value: '))
operator = (input('Enter Operator: '))
val2 = int(input('Enter Second Value: '))
if operator == '+':
print(val1 + val2 ,'answer')
elif operator == '-':
print(val1 - val2 ,'answer')
elif operator == '*':
print(val1 * val2 ,'answer')
elif operator == '/':
print(val1 / val2 ,'answer')
else:
print('Please Enter Valid Operator')
#duplicate values from list
arr = [ 3, 54, 59, 3, 89, 30, 12, 6, 54, 33, 30, 10]
dupItems = []
uniqItems = {}
for i in arr:
if i not in uniqItems:
uniqItems[i] = 1
else:
if uniqItems[i] == 1:
dupItems.append(i)
uniqItems[i] += 1
print(dupItems)