I have a Python question.

Asked 2 years ago, Updated 2 years ago, 66 views

Bloods = ['a', 'b', 'ab', 'o']

i=1
while i<=10:
    list = input('Blood donated (a, b, ab, o) :')
    i+=1
while i>10:
    break

j=1
for i in range(len(list)):
    print(list[j], '', end='')
    j+=1

I did this, but an error appears. I don't think I should write down the "blood type donated" in the list = input, what should I do?

python loops

2022-09-20 16:35

1 Answers

If you enter the command list, it becomes a command to create a list, not to include the elements presented in the list.

I think you need to study the basics a little bit more about what a for statement is, what a while is, and what a list is.

Bloods = ['a', 'b', 'ab', 'o']

i=0
b = []
while i<10:
    a = input('Blood donated (a, b, ab, o) :')
    c = a.lower()
    if c in Bloods:
        b.append(c)
        i+=1

print ('Results')
for i in range(len(b)):
    print(b[i], ' ', end = '')

>> Blood Donated (a, b, ab, o) : a
Blood type donated (a, b, ab, o) : n
Blood type donated (a, b, ab, o) : a
Blood type donated (a, b, ab, o) : n
Blood type donated (a, b, ab, o) : a
Blood type donated (a, b, ab, o) : b
Blood type donated (a, b, ab, o) : a
Blood type donated (a, b, ab, o) : b
Blood type donated (a, b, ab, o) : b
Blood type donated (a, b, ab, o) : o
Blood type donated (a, b, ab, o) : o
Blood type donated (a, b, ab, o) : o
Result
a  a  a  b  a  b  b  o  o  o  


2022-09-20 16:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.