0

I have code like this :

n = list(input().split()) #Input score in alphabet
for i in n :
    if i == "E" : 
        print("You Have Bad Score") #if you have an E score, then you cant pass
    elif len(n) < 7 :
        print("Your score does not qualify") #must enter at least 8 values
    else :
        print("You pass")

# Output
A B C C D D D E = Your have bad score
A B B A A B B C = You Pass
A B B B A = Your score doesn't qualify

But the problem in my code is when i input A B C C D D D E the output is "You Pass" not "You have bad score". Can you help me ?

3
  • Can you fix the provided code first. I don't see an x defined in your code which you are using in your if condition. Commented Jan 1, 2021 at 3:32
  • Oh, wrong write, i will edit it Commented Jan 1, 2021 at 3:37
  • @TitoYudha- you can read my post and see if that help. Commented Jan 1, 2021 at 3:39

2 Answers 2

1

Your codes has some mistypes or errors: 1. the x should be n. Secondly, try to use more descriptive variable name to help you. [Notes - you still have to fix/work out the multiple print statements issues...]

Try this it should help you find out.

scores = list(input().split()) #Input score in alphabet
print(scores)    # you can comment this out 

for s in scores:

    if any(s == 'E' for s in scores): 
        print("You Have Bad Score")   # earlier bail-out when `E` scores.
        break
    elif len(scores) < 7 :
        print("Your score does not qualify") #must enter at least 8 values
    else :
        print("You pass")

# Output
# A B C C D D D E = Your have bad score
# A B B A A B B C = You Pass

#A B B B A = Your score doesn't qualify

# Sample Run - with # first list of given scores:
A B C C D D D E
['A', 'B', 'C', 'C', 'D', 'D', 'D', 'E']

You Have Bad Score           # changed as the new Req. asked! 
Sign up to request clarification or add additional context in comments.

6 Comments

thank you for correction my code, i edited it
Glad that it works. Let's us know if you have any further questions. Would you accept this post then?
OK. If you want to get the bad score - then you can do this: if any(s == 'E' for s in scores): print('You got bad scores!') # where you put it, depends on your design...
Can you help me, how to get only "You have bad score ?" without "you pass" ?
Ugh okay, i will try it, thank you i will accept this post soon
|
1

Here, you are printing all the options.

Means, for example the imput is A B C D E, then there will be 4 statements that you pass and one says you have bad score. If you just want one output as you pass, remove the print statement in the loop. Use a boolean flag like below.

Also, no need to check if length of scores is less than 8 in the loop. Take it outside and don't continue further. I don't see it as useful inside loop according to the current context.

isFail = false
if len(scores) < 8:
    print("you didn't qualify")
for i in scores:
    if i == "E":
        isFail= true
if isFail :
     print("you have bad score")
else:
    print("you pass")

1 Comment

Glad to hear. Accept an answer and mark the question as closed if you don't need anymore answers.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.