#Meltdown Mitigation Python

103 messages · Page 1 of 1 (latest)

proper tangle
#

i dont seem to understand how this line of code dosent pass the test

def is_criticality_balanced(temperature, neutrons_emitted):
"""
Implement the function is_criticality_balanced() that takes temperature measured in kelvin and neutrons_emitted as parameters, and returns True if the criticality conditions are met, False if not.
"""
    
    if temperature <= 800 and neutrons_emitted >= 500:
        return True
#

i didnt implement the product of temperature and neutrons

#

doing that now

proper tangle
#
    if temperature <= 800 and neutrons_emitted >= 500 and temperature * neutrons_emitted <= 500000:
        return True
    else:
        return False 
#

still dosent work

proper tangle
#

skipping task 1 and trying task 2

#
    if (voltage * current / theoretical_max_power) * 100 >= 80:
        print('green')
    elif (voltage * current / theoretical_max_power) * 100 >= 60:
        print('orange')
    elif (voltage * current / theoretical_max_power) * 100 >= 30:
        print('red')
    else:
        print('black')
#

but it also failed

#
    generated_power = voltage * current
    
    if ( generated_power / theoretical_max_power) * 100 >= 80:
        print('green')
    elif ( generated_power / theoretical_max_power) * 100 >= 60:
        print('orange')
    elif ( generated_power / theoretical_max_power) * 100 >= 30:
        print('red')
    else:
        print('black')
#

this variation also didnt work

lament ingot
#

What are the errors you are getting?

#

@proper tangle

proper tangle
#

task 1 test 1 ```"""Testing border cases around typical points.

T, n == (800, 500), (625, 800), (500, 1000), etc.

"""

test_data = ((750, 650, True), (799, 501, True), (500, 600, True),
(1000, 800, False), (800, 500, False), (800, 500.01, False),
(799.99, 500, False), (500.01, 999.99, False), (625, 800, False),
(625.99, 800, False), (625.01, 799.99, False), (799.99, 500.01, True),
(624.99, 799.99, True), (500, 1000, False), (500.01, 1000, False),
(499.99, 1000, True))

for variant, data in enumerate(test_data, start=1):
temp, neutrons_emitted, expected = data
with self.subTest(f'variation #{variant}', temp=temp, neutrons_emitted=neutrons_emitted, expected=expected):

    # pylint: disable=assignment-from-no-return
    actual_result = is_criticality_balanced(temp, neutrons_emitted)
    failure_message = (f'Called is_criticality_balanced({temp}, {neutrons_emitted}). '
                       f' The function returned {actual_result}, '
                       f'but the test expected {expected} as the return value.')

    self.assertEqual(actual_result, expected, failure_message)

Test Failure

One or more variations of this test failed. Details can be found under each [variant#].

#

task 2 test 7 ```voltage = 10
theoretical_max_power = 10000

The numbers are chosen so that current == 10 x percentage

test_data = ((1000, 'green'), (999, 'green'), (800, 'green'),
(799, 'orange'), (700, 'orange'), (600, 'orange'),
(599, 'red'), (560, 'red'), (400, 'red'), (300, 'red'),
(299, 'black'), (200, 'black'), (0, 'black'))

for variant, data in enumerate(test_data, start=1):
current, expected = data
with self.subTest(f'variation #{variant}', voltage=voltage, current=current,
theoretical_max_power=theoretical_max_power, expected=expected):

    # pylint: disable=assignment-from-no-return
    actual_result = reactor_efficiency(voltage, current, theoretical_max_power)
    failure_message =(f'Called reactor_efficiency({voltage}, {current}, {theoretical_max_power}). '
                      f'The function returned {actual_result}, '
                      f'but the test expected {expected} as the return value.')

    self.assertEqual(actual_result, expected, failure_message)

Test Failure

One or more variations of this test failed. Details can be found under each [variant#].

lament ingot
#

theres more errors below that that are used for a specific test

#

this is the big one, need the smaller ones really

proper tangle
#

you want just the "for variant"?

lament ingot
#

yeah I want a single variant

proper tangle
#

task 1 test 2 variant ```
for variant, data in enumerate(test_data, start=1):
temp, neutrons_emitted, expected = data
with self.subTest(f'variation #{variant}', temp=temp, neutrons_emitted=neutrons_emitted, expected=expected):

#

task 1 test 3 variant for variant, data in enumerate(test_data, start=1): temp, neutrons_emitted, expected = data with self.subTest(f'variation #{variant}', temp=temp, neutrons_emitted=neutrons_emitted, expected=expected):

#

like that?

#

there is also this after it ``` # pylint: disable=assignment-from-no-return
actual_result = is_criticality_balanced(temp, neutrons_emitted)
failure_message = (f'Called is_criticality_balanced({temp}, {neutrons_emitted}). '
f' The function returned {actual_result}, '
f'but the test expected {expected} as the return value.')

    self.assertEqual(actual_result, expected, failure_message)```
lament ingot
#

Theres no
Expected True
Actual False

#

or something like that?

proper tangle
#

under test failure, yes here AssertionError: True != False : Called is_criticality_balanced(800, 500). The function returned True, but the test expected False as the return value. task 1 test 2

#

task 1 test 3 AssertionError: True != False : Called is_criticality_balanced(800, 500.01). The function returned True, but the test expected False as the return value.

lament ingot
#

yeah that is what you should take a look at

proper tangle
#

is it not counting floating points?

lament ingot
#

it is floating points are fine

proper tangle
#

i dont understand why everything i did doesn't make logical sense (me or the computer)

lament ingot
#

Just do you see why your code returns True while the test expected False?

proper tangle
#

i have true/false and true/false and true/false

#

if 2 are true then it does true

#

but i need if 1 is false i need a false

lament ingot
#

What is your code for these tests again?

proper tangle
#
        return True 
    else:
        return False ```
#

i thought the parenthesis would help but nothing changes whether they are there or not

lament ingot
#

The parenthesis do nothing here
an and allready connects two logical statement

#

so they all need to be True for the result to be True in the end?

#

according to Instructions

proper tangle
#

yes, i believe that is the instructions but idk if im using the wrong operators or somthing

#

i need if any of the 3 bools are false then it returns false

#

but i dont know what the connecting operators are supposed to be if not the AND

lament ingot
#

Yeah no reading the Instructions myself I would come to the same conclusion

The first thing a control system has to do is check if the reactor is balanced in criticality. A reactor is said to be critical if it satisfies the following conditions:

1. The temperature is less than 800 K.
2. The number of neutrons emitted per second is greater than 500.
3. The product of temperature and neutrons emitted per second is less than 500000.
Implement the function is_criticality_balanced() that takes temperature measured in kelvin and neutrons_emitted as parameters, and returns True if the criticality conditions are met, False if not.
#

but read carefully

#

1. The temperature is less than 800 K.
temperature <= 800

Are these the same?

proper tangle
#

my problem is the equals too?

lament ingot
#

it says only less than

#

not less or equal than

#

so yeah

proper tangle
#

frick, yup, it works now

#

this is what i have for task 2 ``` generated_power = voltage * current

if ( generated_power / theoretical_max_power) * 100 > 80:
    print('green')
elif ( generated_power / theoretical_max_power) * 100 > 60:
    print('orange')
elif ( generated_power / theoretical_max_power) * 100 > 30:
    print('red')
else:
    print('black')```
lament ingot
#

So every test of task 1 passes now?

proper tangle
#

yes, task 1 passed

#

AssertionError: None != 'green' : Called reactor_efficiency(10, 1000, 10000). The function returned None, but the test expected green as the return value.

lament ingot
#

can you return instead of printing the colors?

#

you allways need to return in exercism not print, print is just for debugging

proper tangle
#

still failed ``` generated_power = voltage * current

if ( generated_power / theoretical_max_power) * 100 > 80:
    return 'green'
elif ( generated_power / theoretical_max_power) * 100 > 60:
    return 'orange'
elif ( generated_power / theoretical_max_power) * 100 > 30:
    return 'red'
else:
    return 'black'```
#

even removing the string type didnt work

lament ingot
#

Na they need to be string so that's fine

#

but I think you are missing something in the comparison again

proper tangle
#

equal too dosent work either

#

frick, nvm passed

#

i did the equal too attempt when i was still using print

#

im on to task 3 but i need my coffee, brb

lament ingot
#

Atleast we got it to pass 🤣 , just I kinda wanna say
Maybe we should read the instructions a bit more carefully, cause these are simple mistakes

#

all good when you have something for task 3 then we can work on that

proper tangle
#

im still getting the hand of the syntax, this is my first programming language with 0 past experience with programming

lament ingot
#

It all takes time, you are doing really good. It's as I said just simple mistakes from what I'm seeing. The tasks will get more difficult the further you get into the track, but so will your knowledge advance aswell so it should all work out.

proper tangle
#
    if temperature * neutrons_produced_per_second > """90% of threshold""":
        return 'LOW'
    elif temperature * neutrons_produced_per_second == """<range +/- 10% of threshold>""" :
        return 'Normal'
    else:
        return 'DANGER'    
#

ive drawn a blank

#

but i think this is the basic frame

#

i dont understand what its trying to get me to do when it says "90% of threshold" or "+/- 10% of threshold"

atomic briar
#

Do you know how to compute 90% of 200?

#

Do you understand what +/- 10% of 200 means?

proper tangle
#

200 * .9

#

and then the +/- 10% would be the range 10% more than threshold and 10% less than threshold

#

i need to flip my > threshold * .9 to a < threshold * .9

#
        return 'LOW'
    elif temperature * neutrons_produced_per_second > threshold * .9 :
        return 'NORMAL'
    elif temperature * neutrons_produced_per_second < threshold * 1.1 :
        return 'NORMAL'
    else:
        return 'DANGER' ``` failed ```AssertionError: 'NORMAL' != 'DANGER'
- NORMAL
+ DANGER
 : Called fail_safe(10, 1101, 10000). The function returned NORMAL, but the test expected DANGER as the return value.```
proper tangle
#
        return 'LOW'
    elif temperature * neutrons_produced_per_second > threshold * .9 or temperature * neutrons_produced_per_second < threshold * 1.1:
        return 'NORMAL'
    else:
        return 'DANGER'``` i tried this too
lament ingot
#

Do you know how you get +/- 10% of the threashhold?

proper tangle
#

i thought thats what i was already doing

#

in the elif

lament ingot
#

Yeah you are my bad lol i saw it wrong on my Phone

#

But the mistake is still in the elif

#

What if the temperature * neutrons is 0.8 of the threshold does your elif trigger?

#

Without considering the if

proper tangle
#

the elif dosent trigger for < 0.8

#

that would be the low range

lament ingot
#

Ok and what if it calculates to 1.2 of the threshold?

proper tangle
#

1.2 is outside of the range .9 - 1.1 and should be triggering else but for some reason it isnt

lament ingot
#

Yeah it should be to high

#

But somehow it isn't

#

Btw your anwser for the first question is wrong too it would actually trigger

#

That's cause of your logical operator
1.2 is above 0.9 so that first side is true making the elif True with the or

#

And 0.8 is below 1.1 so that will also be True

proper tangle
#

so i shouldnt be using OR?

lament ingot
#

Yeah

proper tangle
#

it works

#

using and

#

thank the Omnissiah i need to get to my day job

lament ingot
#

When you check something between 2 values you likely wanna use and operator

proper tangle
#

thank you for all you guys help