How to print the updated output
Question:
I need help with my code because it doesn’t print the updated output
For example:
Enter First name: Cid
Enter Middle name: RAZOR
Enter Last name: Kamisato
Enter number of subjects: 1
Please enter this valid subjects: ['CC1', 'CC2', 'CC3', 'CC4', 'CC5']
Please enter the subject: cc1
**** This is your info *****
First name is: Cid
Middle name is: RAZOR
Last name is: Kamisato
Your Selected Subjects are: ['cc1']
Do you want to change anything?(Y/N): y
1. Change First name
2. Change Middle name
3. Change Last name
4. Change number of subjects & change the subjects
5. Exit
What do you want to change?: 1
Enter First name: CID
****** This is your updated info *******
First name is: CID
Middle name is: RAZOR
Last name is: Kamisato
Number of subjects: 1
Your Selected Subjects are: ['cc1']
Do you want to change anything?(Y/N): y
1. Change First name
2. Change Middle name
3. Change Last name
4. Change number of subjects & change the subjects
5. Exit
What do you want to change?: 2
Enter Middle name: razor
****** This is your updated info *******
This is your first name: Cid
Middle name is: razor
Last name is: Kamisato
Number of subjects: 1
Your Selected Subjects are: ['cc1']
Do you want to change anything?(Y/N):
I want the updated CID name to be printed in the updated output and so on.
F_name = []
M_name = []
L_name = []
o_sub = []
no_sub = []
subjects = ['CC1', 'CC2', 'CC3', 'CC4', 'CC5']
name = input('Enter First name: ')
F_name.append(name)
mid_name = input('Enter Middle name: ')
M_name.append(mid_name)
last_name = input('Enter Last name: ')
L_name.append(last_name)
n_sub = int(input('Enter number of subjects: '))
if n_sub <= 5:
print(f'Please enter this valid subjects: {subjects}')
no_sub.append(n_sub)
else:
print('INVALID INPUT!!!')
print('MAX IS 5!!!')
exit()
for i in range(n_sub):
sub = input('Please enter the subject: ')
if sub.upper() in subjects:
o_sub.append(sub)
else:
print('INVALID INPUT')
break
print('**** This is your info *****')
print(f'First name is: {name}')
print(f'Middle name is: {mid_name}')
print(f'Last name is: {last_name}')
print(f'Your Selected Subjects are: {o_sub}')
while True:
choice = input('Do you want to change anything?(Y/N): ')
if choice.casefold() == 'y':
print('1. Change First name')
print('2. Change Middle name')
print('3. Change Last name')
print('4. Change number of subjects & change the subjects ')
print('5. Exit')
else:
print('------THANK YOU FOR USING ME------!!!')
exit()
option1 = input('What do you want to change?: ')
if option1 == '1':
cf_name = str(input('Enter First name: '))
F_name.clear()
F_name.append(cf_name)
print('****** This is your updated info *******')
print(f'First name is: {cf_name}')
print(f'Middle name is: {mid_name}')
print(f'Last name is: {last_name}')
print(f'Number of subjects: {n_sub}')
print(f'Your Selected Subjects are: {o_sub}')
elif option1 == '2':
cm_name = input('Enter Middle name: ')
M_name.clear()
M_name.append(cm_name)
print('****** This is your updated info *******')
print(f'This is your first name: {name}')
print(f'Middle name is: {cm_name}')
print(f'Last name is: {last_name}')
print(f'Number of subjects: {n_sub}')
print(f'Your Selected Subjects are: {o_sub}')
elif option1 == '3':
cl_name = input('Enter Last name: ')
L_name.clear()
L_name.append(cl_name)
print('****** This is your updated info *******')
print(f'This is your first name: {name}')
print(f'Middle name is: {mid_name}')
print(f'Last name is: {cl_name}')
print(f'Number of subjects: {n_sub}')
print(f'Your Selected Subjects are: {o_sub}')
elif option1 == '4':
no_sub.clear()
o_sub.clear()
var = int(input('Enter the number of subjects: '))
no_sub.append(var)
if var <= 5:
for i in range(var):
sub1 = input('Please enter the subject: ')
if sub1.upper() in subjects:
o_sub.append(sub1)
else:
print('INVALID INPUT')
break
print('****** This is your updated info *******')
print(f'This is your first name: {name}')
print(f'Middle name is: {mid_name}')
print(f'Last name is: {last_name}')
print(f'Number of subjects: {var}')
print(f'Your Selected Subjects are: {o_sub}')
else:
print('INVALID INPUT')
print('MAX IS 5!!')
exit()
elif option1 == '5':
print('====== THANK YOU FOR USING ME ======')
exit()
Answers:
When you change one of the fields, you use a different variable than the one you use when printing out the info after changing other fields. E.g. you assign the new first name to cf_name
, but the rest of the code expects it to be in name
. You need to use the same variable consistently.
So change
if option1 == '1':
cf_name = str(input('Enter First name: '))
F_name.clear()
F_name.append(cf_name)
print('****** This is your updated info *******')
print(f'First name is: {cf_name}')
print(f'Middle name is: {mid_name}')
print(f'Last name is: {last_name}')
print(f'Number of subjects: {n_sub}')
print(f'Your Selected Subjects are: {o_sub}')
to
if option1 == '1':
name = str(input('Enter First name: '))
F_name.clear()
F_name.append(name)
print('****** This is your updated info *******')
print(f'First name is: {name}')
print(f'Middle name is: {mid_name}')
print(f'Last name is: {last_name}')
print(f'Number of subjects: {n_sub}')
print(f'Your Selected Subjects are: {o_sub}')
And change the other options similarly.
I need help with my code because it doesn’t print the updated output
For example:
Enter First name: Cid
Enter Middle name: RAZOR
Enter Last name: Kamisato
Enter number of subjects: 1
Please enter this valid subjects: ['CC1', 'CC2', 'CC3', 'CC4', 'CC5']
Please enter the subject: cc1
**** This is your info *****
First name is: Cid
Middle name is: RAZOR
Last name is: Kamisato
Your Selected Subjects are: ['cc1']
Do you want to change anything?(Y/N): y
1. Change First name
2. Change Middle name
3. Change Last name
4. Change number of subjects & change the subjects
5. Exit
What do you want to change?: 1
Enter First name: CID
****** This is your updated info *******
First name is: CID
Middle name is: RAZOR
Last name is: Kamisato
Number of subjects: 1
Your Selected Subjects are: ['cc1']
Do you want to change anything?(Y/N): y
1. Change First name
2. Change Middle name
3. Change Last name
4. Change number of subjects & change the subjects
5. Exit
What do you want to change?: 2
Enter Middle name: razor
****** This is your updated info *******
This is your first name: Cid
Middle name is: razor
Last name is: Kamisato
Number of subjects: 1
Your Selected Subjects are: ['cc1']
Do you want to change anything?(Y/N):
I want the updated CID name to be printed in the updated output and so on.
F_name = []
M_name = []
L_name = []
o_sub = []
no_sub = []
subjects = ['CC1', 'CC2', 'CC3', 'CC4', 'CC5']
name = input('Enter First name: ')
F_name.append(name)
mid_name = input('Enter Middle name: ')
M_name.append(mid_name)
last_name = input('Enter Last name: ')
L_name.append(last_name)
n_sub = int(input('Enter number of subjects: '))
if n_sub <= 5:
print(f'Please enter this valid subjects: {subjects}')
no_sub.append(n_sub)
else:
print('INVALID INPUT!!!')
print('MAX IS 5!!!')
exit()
for i in range(n_sub):
sub = input('Please enter the subject: ')
if sub.upper() in subjects:
o_sub.append(sub)
else:
print('INVALID INPUT')
break
print('**** This is your info *****')
print(f'First name is: {name}')
print(f'Middle name is: {mid_name}')
print(f'Last name is: {last_name}')
print(f'Your Selected Subjects are: {o_sub}')
while True:
choice = input('Do you want to change anything?(Y/N): ')
if choice.casefold() == 'y':
print('1. Change First name')
print('2. Change Middle name')
print('3. Change Last name')
print('4. Change number of subjects & change the subjects ')
print('5. Exit')
else:
print('------THANK YOU FOR USING ME------!!!')
exit()
option1 = input('What do you want to change?: ')
if option1 == '1':
cf_name = str(input('Enter First name: '))
F_name.clear()
F_name.append(cf_name)
print('****** This is your updated info *******')
print(f'First name is: {cf_name}')
print(f'Middle name is: {mid_name}')
print(f'Last name is: {last_name}')
print(f'Number of subjects: {n_sub}')
print(f'Your Selected Subjects are: {o_sub}')
elif option1 == '2':
cm_name = input('Enter Middle name: ')
M_name.clear()
M_name.append(cm_name)
print('****** This is your updated info *******')
print(f'This is your first name: {name}')
print(f'Middle name is: {cm_name}')
print(f'Last name is: {last_name}')
print(f'Number of subjects: {n_sub}')
print(f'Your Selected Subjects are: {o_sub}')
elif option1 == '3':
cl_name = input('Enter Last name: ')
L_name.clear()
L_name.append(cl_name)
print('****** This is your updated info *******')
print(f'This is your first name: {name}')
print(f'Middle name is: {mid_name}')
print(f'Last name is: {cl_name}')
print(f'Number of subjects: {n_sub}')
print(f'Your Selected Subjects are: {o_sub}')
elif option1 == '4':
no_sub.clear()
o_sub.clear()
var = int(input('Enter the number of subjects: '))
no_sub.append(var)
if var <= 5:
for i in range(var):
sub1 = input('Please enter the subject: ')
if sub1.upper() in subjects:
o_sub.append(sub1)
else:
print('INVALID INPUT')
break
print('****** This is your updated info *******')
print(f'This is your first name: {name}')
print(f'Middle name is: {mid_name}')
print(f'Last name is: {last_name}')
print(f'Number of subjects: {var}')
print(f'Your Selected Subjects are: {o_sub}')
else:
print('INVALID INPUT')
print('MAX IS 5!!')
exit()
elif option1 == '5':
print('====== THANK YOU FOR USING ME ======')
exit()
When you change one of the fields, you use a different variable than the one you use when printing out the info after changing other fields. E.g. you assign the new first name to cf_name
, but the rest of the code expects it to be in name
. You need to use the same variable consistently.
So change
if option1 == '1':
cf_name = str(input('Enter First name: '))
F_name.clear()
F_name.append(cf_name)
print('****** This is your updated info *******')
print(f'First name is: {cf_name}')
print(f'Middle name is: {mid_name}')
print(f'Last name is: {last_name}')
print(f'Number of subjects: {n_sub}')
print(f'Your Selected Subjects are: {o_sub}')
to
if option1 == '1':
name = str(input('Enter First name: '))
F_name.clear()
F_name.append(name)
print('****** This is your updated info *******')
print(f'First name is: {name}')
print(f'Middle name is: {mid_name}')
print(f'Last name is: {last_name}')
print(f'Number of subjects: {n_sub}')
print(f'Your Selected Subjects are: {o_sub}')
And change the other options similarly.