1

Guys I am trying to realise given input should loop through my float list named enerji and print out the first element if it is less than it and 1 before element of it. (edit y=82 in my case it is deffined above but not seen) here is the code:

    a = 0
    input_bigger_than_energy = False
    while a!= y and not(input_bigger_than_energy):
        energy = float(input('write down interwal of energy between 1000 and 
    100000000000:'))
        if energy > enerji[a]:
            a=a+1
        else:
            input_bigger_than_energy = True
    print(a)
    print(enerji[a])
    print(enerji[a-1])



enerji = [1000.0, 1500.0, 1838.8, 1838.9, 2000.0, 3000.0, 4000.0, 5000.0, 6000.0, 8000.0, 10000.0, 15000.0, 20000.0, 30000.0, 40000.0, 50000.0, 60000.0, 80000.0, 100000.0, 150000.0, 200000.0, 300000.0, 400000.0, 500000.0, 600000.0, 800000.0, 1000000.0, 1022000.0, 1250000.0, 1500000.0, 2000000.0, 2044000.0, 3000000.0, 4000000.0, 5000000.0, 6000000.0, 7000000.0, 8000000.0, 9000000.0, 10000000.0, 11000000.0, 12000000.0, 13000000.0, 14000000.0, 15000000.0, 16000000.0, 18000000.0, 20000000.0, 22000000.0, 24000000.0, 26000000.0, 28000000.0, 30000000.0, 40000000.0, 50000000.0, 60000000.0, 80000000.0, 100000000.0, 150000000.0, 200000000.0, 300000000.0, 400000000.0, 500000000.0, 600000000.0, 800000000.0, 1000000000.0, 1500000000.0, 2000000000.0, 3000000000.0, 4000000000.0, 5000000000.0, 6000000000.0, 8000000000.0, 10000000000.0, 15000000000.0, 20000000000.0, 30000000000.0, 40000000000.0, 50000000000.0, 60000000000.0, 80000000000.0, 100000000000.0]

problem code works but it is asking me again to input

2
  • 2
    Can you reformat your code, or re-paste it? It's hard to tell where your while loop begins and ends. As for why you get asked for input again, my guess is that you're missing a break. Also, I don't see where i is defined at all. In essence, your condition on the while loop isn't evaluating like you think it is. Commented Aug 25, 2018 at 0:05
  • my bad it should be 'a' instead of 'i' corrected it but still having the same problem Commented Aug 25, 2018 at 0:28

1 Answer 1

1

You have the input statement inside the loop; it will ask for an input for every time it loops.

Also, the variable y is never set to a value.

# Shortened the list of example data
enerji = [1000.0, 1500.0, 1838.8, 1838.9, 2000.0, 3000.0, 4000.0]

a = 0
input_bigger_than_energy = False
y = 10  # Guessing a value for unknown variable

energy = float(input('write down interwal of energy between 1000 and 100000000000: '))
while a != y and not(input_bigger_than_energy):
    if energy > enerji[a]:
        a=a+1
    else:
        input_bigger_than_energy = True

print(a)
print(enerji[a])
print(enerji[a-1])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.