Hello, I have been working on this code for a while now and I have encountered difficulties in getting it to function as intended. Can someone help me with this code and how to fix it? The code I currently have is: import math cs_cred = 0 print("--------------------------------") print(" UIC CS Track") print("--------------------------------\n") print("QUESTION 1") answer_1 = str.upper(input("Are you a CS major? (Yes or No): ")) answer_2 = "" answer_3 = "" answer_4 = "" answer_5 = "" answer_6 = "" answer_7 = "" CS_277 = "" CS_377 = "" CS_401 = "" answer_8 = "" if answer_1 == "YES": print("\nQUESTION 2") answer_2 = str.upper(input("Have you taken ENGR100? (Yes or No): ")) if answer_2 == "YES" or "NO": print("\nQUESTION 3") answer_3 = str.upper(input("Have you taken CS111? (Yes or No): ")) if answer_3 == "YES" or "NO": print("\nQUESTION 4") answer_4 = str.upper(input("Have you taken CS141? (Yes or No): ")) if answer_4 == "YES" or "NO": print("\nQUESTION 5") answer_5 = str.upper(input("Have you taken CS151? (Yes or No): ")) if answer_5 == "YES" or "NO": print("\nQUESTION 6") answer_6 = str.upper(input("Have you taken CS211? (Yes or No): ")) if answer_6 == "YES" or "NO": print("\nQUESTION 7") answer_7 = str.upper(input("Have you taken CS251? (Yes or No): ")) CS_277 = str.upper(input("Have you taken CS277? (Yes or No): ")) CS_377 = str.upper(input("Have you taken CS377? (Yes or No): ")) CS_401 = str.upper(input("Have you taken CS401? (Yes or No): ")) if answer_7 or CS_277 or CS_377 or CS_401 == "YES" or "NO": print("\nQUESTION 8") answer_8 = str.upper(input("Have you taken CS261? (Yes or No): ")) print("\n--------------------------------") print(" Summary") print("--------------------------------\n") if answer_1 == "YES": print("You are a CS major!") elif answer_1 == "NO": print("Sadly, you are not a CS major.") if answer_2 == "NO": print("Do not forget to take ENGR100!") if answer_3 == "YES": cs_cred += 3 if answer_4 == "YES": cs_cred += 3 if answer_5 == "YES": cs_cred += 3 if answer_6 == "YES": cs_cred += 3 if answer_7 == "YES": cs_cred += 4 if CS_277 == "YES": cs_cred += 3 if CS_377 == "YES": cs_cred += 3 if CS_401 == "YES": cs_cred += 3 if answer_8 == "YES": cs_cred += 4 if answer_1 == "YES":\ print("\nRequired CS credits earned: " + str(cs_cred)+".") else: # Print the summary for non-CS majors print("\n--------------------------------")
Hello, I have been working on this code for a while now and I have encountered difficulties in getting it to function as intended. Can someone help me with this code and how to fix it?
The code I currently have is:
There are a few issues with the code which are given below:
1. In the if conditions of answer_2, answer_3, answer_4, answer_5, answer_6, answer_7, CS_277, CS_377, CS_401, answer_8, the condition should be checked separately for each option. So, instead of answer_2 == "YES" or "NO", it should be answer_2 == "YES" or answer_2 == "NO". Fix this issue in all the if conditions.
2. The line if answer_7 or CS_277 or CS_377 or CS_401 == "YES" or "NO": has a logical mistake. The correct condition should be if answer_7 == "YES" or CS_277 == "YES" or CS_377 == "YES" or CS_401 == "YES" or answer_7 == "NO" or CS_277 == "NO" or CS_377 == "NO" or CS_401 == "NO":. Fix this condition accordingly.
3. In the line if answer_1 == "YES":\, there is an unnecessary backslash at the end of the line. Remove the backslash.
Step by step
Solved in 4 steps with 3 images