-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-practice.py
More file actions
154 lines (113 loc) · 5.02 KB
/
python-practice.py
File metadata and controls
154 lines (113 loc) · 5.02 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import operator
import random
#########################################PLEASE READ THE CONTENT GIVEN BELOW############################################################
#I used this code in a task in GCI 2018, but now since I havent done advanced python since a long time so i have forgotten a bit but I will recall it after some practice
#########################################################################################################################################
def readStudentDetails():
print()
# { 'John': 600, 'Ben': 800, 'David': 950, 'Mark': 980}
print("Enter the number of students: ")
numberOfStudents = int(input())
studentRecord = {}
for student in range(0, numberOfStudents):
print("Enter the name of the student: ")
name = input()
print("Enter the marks of students: ")
marks = int(input())
studentRecord[name] = marks
print()
return studentRecord
def rankStudents(studentRecord):
try:
print()
# [('Mark', 980), ('David', 950), ('Ben', 800), ('John', 600)]
sortedStudentRecord = sorted(studentRecord.items(), key = operator.itemgetter(1), reverse = True)
print(sortedStudentRecord)
print("{} has secured first rank, scoring {} marks".format(sortedStudentRecord[0][0], sortedStudentRecord[0][1]))
print("{} has secured second rank, scoring {} marks".format(sortedStudentRecord[1][0], sortedStudentRecord[1][1]))
print("{} has secured third rank, scoring {} marks".format(sortedStudentRecord[2][0], sortedStudentRecord[2][1]))
print()
return sortedStudentRecord
except IndexError:
print("Enter a minimum of 3 students")
quit()
def rewardStudents(sortedStudentRecord, reward):
print()
print("{} has received a cash reward of ${}".format(sortedStudentRecord[0][0], reward[0]))
print("{} has received a cash reward of ${}".format(sortedStudentRecord[1][0], reward[1]))
print("{} has received a cash reward of ${}".format(sortedStudentRecord[2][0], reward[2]))
print()
def appreciateStudents(sortedStudentRecord):
print()
for record in sortedStudentRecord:
if record[1] >= 950:
print("Congratulations on scoring {} marks, {}".format(record[1], record[0]))
else:
break
print()
studentRecord = readStudentDetails()
sortedStudentRecord = rankStudents(studentRecord)
reward = (500, 300, 100)
rewardStudents(sortedStudentRecord, reward)
appreciateStudents(sortedStudentRecord)
import operator
import random
def readStudentDetails():
print()
# { 'John': 600, 'Ben': 800, 'David': 950, 'Mark': 980}
print("Enter the number of students: ")
numberOfStudents = int(input())
studentRecord = {}
for student in range(0, numberOfStudents):
print("Enter the name of the student: ")
name = input()
print("Enter the marks of students: ")
marks = int(input())
studentRecord[name] = marks
print()
return studentRecord
def rankStudents(studentRecord):
try:
print()
# [('Mark', 980), ('David', 950), ('Ben', 800), ('John', 600)]
sortedStudentRecord = sorted(studentRecord.items(), key = operator.itemgetter(1), reverse = True)
print(sortedStudentRecord)
print("{} has secured first rank, scoring {} marks".format(sortedStudentRecord[0][0], sortedStudentRecord[0][1]))
print("{} has secured second rank, scoring {} marks".format(sortedStudentRecord[1][0], sortedStudentRecord[1][1]))
print("{} has secured third rank, scoring {} marks".format(sortedStudentRecord[2][0], sortedStudentRecord[2][1]))
print()
return sortedStudentRecord
except IndexError:
print("Enter a minimum of 3 students")
quit()
def rewardStudents(sortedStudentRecord, reward):
print()
print("{} has received a cash reward of ${}".format(sortedStudentRecord[0][0], reward[0]))
print("{} has received a cash reward of ${}".format(sortedStudentRecord[1][0], reward[1]))
print("{} has received a cash reward of ${}".format(sortedStudentRecord[2][0], reward[2]))
print()
def appreciateStudents(sortedStudentRecord):
print()
for record in sortedStudentRecord:
if record[1] >= 950:
print("Congratulations on scoring {} marks, {}".format(record[1], record[0]))
else:
break
print()
studentRecord = readStudentDetails()
sortedStudentRecord = rankStudents(studentRecord)
reward = (500, 300, 100)
rewardStudents(sortedStudentRecord, reward)
appreciateStudents(sortedStudentRecord)
############################################################################
def lottery():
d = ["John", "Dan", "David", "Simon", "Benedict"]
abc = random.choice(d)
print("Conratulation", abc, "on winning the lottery" )
lottery()
############################################################################
def lottery():
d = ["John", "Dan", "David", "Simon", "Benedict"]
abc = random.choice(d)
print("Conratulation", abc, "on winning the lottery" )
lottery()