-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay_6_Revision.py
More file actions
110 lines (101 loc) · 2.18 KB
/
Copy pathDay_6_Revision.py
File metadata and controls
110 lines (101 loc) · 2.18 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
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
#Sum of a list
nums = [10, 20, 30, 40]
sum=0
for i in range(len(nums)):
sum=sum+nums[i]
print(sum)
#Count vowels
name = "education"
count=0
for i in range(len(name)):
if name[i] in "aeiou":
count+=1
print(count)
#Pass/Fail Function
def check_result(marks):
if marks>=30:
return "Pass"
else:
return "Fail"
marks=int(input("Enter the marks: "))
print(check_result(marks))
#Reverse a number
a=1234
print(str(a)[::-1])
#or
num = 1234
rev = 0
while num > 0:
digit = num % 10
rev = rev * 10 + digit
num = num // 10
print(rev)
#dict
students = {
"Aditya": 85,
"Rahul": 30,
"Aman": 72
}
for i in students:
print(f"{i} got {students[i]} marks")
#we can also use to call key value directly
for key, value in students.items():
print(f"{key} {value}")
#Count failed students
for key in students:
if students[key]<40:
print(students[key])
#Find topper
for key in students:
if students[key]==max(students.values()):
print(f"{key} is the topper {students[key]}")
#Mini Project
students = {
"Aditya": 85,
"Rahul": 30,
"Aman": 72,
"Priya": 95
}
# Print Pass/Fail for each student
for i in students:
if students[i]>=40:
print(f"{i} passed")
else:
print(f"{i} failed")
# Count passed students
count=0
for i in students:
if students[i]>=40:
count+=1
print(count)
# Count failed students
count=0
for i in students:
if students[i]<40:
count+=1
print(count)
# Find topper
for key in students:
if students[key]==max(students.values()):
print(f"{key} is the topper {students[key]}")
#Student Average
students = {
"Aditya": [80, 90, 70],
"Rahul": [50, 60, 40],
"Priya": [95, 85, 90]
}
for i in students:
sum=0
for j in range(len(students[i])):
sum=sum+students[i][j]
print(f"{i} average is {sum/len(students[i])}")
#Find Overall Topper
for key in students:
if sum(students[key])/len(students[key])==max(students.values()):
print(f"{key} is the topper {sum(students[key])/len(students[key])}")
#Count Students Above Average 75
count=0
for key in students:
if sum(students[key])/len(students[key])>=75:
count+=1
print(count)