-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBasic conceptual code.py
213 lines (178 loc) · 6.23 KB
/
Basic conceptual code.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
s=[] # Insert subjects names
n=[] # Insert marks
u=1 # use to create a document
y=1 # use to assign numbers to the document
t=1 # use to filter the correct numbers
# Create document or not
while u>0:
print('Do you want to create a new document to store results? (y/n)')
choice=input('')
if choice.lower()=='y':
AF=open("Marks.txt","w")
AF.close()
break
elif choice.lower()=='n':
break
else:
continue
p=input('Enter Student Name: ')
# Open a text document
AF=open("Marks.txt","a")
# Insert the Student name into document
AF.write('{0}) Student Name: {1}\n'.format(y,p))
AF.close()
h=int(input('How many subjects do you have? '))
for i in range(1,h+1):
m=input('Enter Subject {0} name: '.format(i))
s.append(str(m))
for i in range(h):
while t>0:
# Input subjects marks
x=input('Enter {0} marks: '.format(s[i]))
# Check the compatibility of the input
if int(x)>=0:
if int(x)<=100:
t+=1
# Assign values to the list 'n'
n.append(int(x))
break
else:
print("You can't input more than 100 values")
continue
elif int(x)<0:
print("You can't input negative values")
continue
# How to return to the while condition when input "String"???
else:
print("You can only input numbers")
continue
# Insert the Subject name and marks into document
AF=open("Marks.txt","a")
for p in range(h):
i=0
AF.write('{0}: {1}\n'.format(s[p],n[i]))
i+=1
AF.close()
# Create loop to the infinity
while True:
# Display the options
print("What do you want? \n1) Max \n2) Min \n3) Total \n4) Avg \n5) Count \n6) New Entry \n7) Finish")
# input only the numbers of the above options
c=int(input("Enter number: "))
# Find Max
if c==1:
def func(a):
global Max
Max=a[0]
for i in range(1,len(a)):
if a[i]>Max:
Max=a[i]
return('The Max value is {0}\n'.format(Max))
print(func(n))
# Open a text document
AF=open("Marks.txt","a")
# Insert the max into document
AF.write('* Max: {0}\n'.format(Max))
AF.close()
# Find Min
elif(c==2):
def func(a):
global Min
Min=a[0]
for i in range(1,len(a)):
if a[i]<Min:
Min=a[i]
return('The Min value is {0}\n'.format(Min))
print(func(n))
# Open a text document
AF=open("Marks.txt","a")
# Insert the max into document
AF.write('* Min: {0}\n'.format(Min))
AF.close()
# Find Total
elif(c==3):
def func(a):
global tot
tot=a[0]
for i in range(1,len(a)):
tot=tot+a[i]
return('The Total is {0}\n'.format(tot))
print(func(n))
# Open a text document
AF=open("Marks.txt","a")
# Insert the max into document
AF.write('* Total: {0}\n'.format(tot))
AF.close()
# Find Avg
elif(c==4):
def func(a):
global avg
avg,tot=0,a[0]
for i in range(1,len(a)):
tot=tot+a[i]
avg=float(tot)/(len(a))
return('The Avarage is {0}\n'.format(avg))
print(func(n))
# Open a text document
AF=open("Marks.txt","a")
# Insert the max into document
AF.write('* Avg: {0}\n'.format(avg))
AF.close()
# Find Count
elif(c==5):
print(' Subject count is {0}\n'.format(len(n)))
# Open a text document
AF=open("Marks.txt","a")
# Insert the max into document
AF.write('* Subject count: {0}\n'.format(len(n)))
AF.close()
# Finish the process
elif c==7:
break
# Delete the current list
elif c==6:
del n # Delete previous 'n'
del s # Delete previous 's'
# Create a new list 'n' and 's'
s=[] # Insert subjects names
n=[] # Insert marks
t=1
y=y+1 # use to update numbers in document
p=input('\nEnter Student Name: ')
# Open a text document
AF=open("Marks.txt","a")
# Insert the Student name into document
AF.write('\n{0}) Student Name: {1}\n'.format(y,p))
AF.close()
h=int(input('How many subjects do you have? '))
for i in range(1,h+1):
m=input('Enter Subject {0} name: '.format(i))
s.append(str(m))
for i in range(h):
while t>0:
# Input new subjects marks
x=input('Enter {0} marks: '.format(s[i]))
# Check the compatibility of the input
if int(x)>=0:
if int(x)<=100:
t+=1
# Assign values to the list 'n'
n.append(int(x))
break
else:
print("You can't input more than 100 values")
continue
elif int(x)<0:
print("You can't input negative values")
continue
# How to return to the while condition when input "String"
else:
print("You can only input numbers")
continue
# Insert the Subject name and marks into document
AF=open("Marks.txt","a")
for p in range(h):
i=0
AF.write('{0}: {1}\n'.format(s[p],n[i]))
i+=1
AF.close()