I'm going to enter my class number and grade and save it in a dictionary and enter my class number again to print out the grade corresponding to that class.
def gra(a):
return
def num(b):
return
dic={}
while True:
c=int(input('Select a menu number>>'))
if c==1:
for i in range(10):
print()
b=int('[%d]th grade<Terminal<Negative>>: '%(i+1))))
if b<=0:
print()
break
else:
print()
a=int (input('Please enter your grade for PL subject'))
dic[b]=a
num(b)
gra(a)
print(dic)
elif c==2:
print()
num=input('Input your number: ')
if num in dic.keys() ==True:
print('##################################################')
print ('# : Subject name: PL #')
print('# Class:----------------------------------#')
print('# : Score #')
print('#------------------------------------------------#')
print('# %s: %d #'%(c,dic.get(num)))
print('##################################################')
After doing this, I did it
Select a menu number>>1
[1]First class number<Termination condition<negative>>: 123456
Please enter your grade for the PL course67
{123456: 67}
[2]First class <Termination condition<negative>>: -1
Select a menu number>>2
Input your number: 123456
Select a menu number>>
As it runs like this, I chose menu 2 and entered the matching school number, but the grades are not printed
Why isn't the report card printed and the menu execution statement appears?
dic
contains number 123456
as a key, but when searching, find the string "123456"
.
Add.
if num in dic.keys() == True:
Due to operator priority,
if num in (dic.keys() == True):
The problem is that it is evaluated as.
Additionally, using an environment such as visual studio code, pycharm, visual studio + python tools, you can check the value of the variables as you proceed one line at a time in debugging mode. Learn how to use convenient tools.
© 2024 OneMinuteCode. All rights reserved.