I have a code that I am running, but for one input value or test vaule it gives 2 false as output:
PS D:\VS Code\Python> & C:/Users/zyx/AppData/Local/Programs/Python/Python310/python.exe "d:/VS Code/Python/dump/dump 1.py"
False
False
PS D:\VS Code\Python>
How do I fix this issue and get just one False as an ouput.
Here's the code:
def count_rotations(nums):
pass
test0 = {
'input': {
'nums': [4,5,1,2,3]
},
'output': 3
}
for test in test0:
print(count_rotations(test0['input']['nums']) == test0['output'])
I am using VS Code.
CodePudding user response:
it can give back-to-back false because of your dictionary test0 which contains two keys so the loop runs 2 times and matches the same condition, if you follow a specific code it is the same as yours and give single False because of one Key.
def count_rotations(nums):
pass
test0 = {
'input': {
'nums': [4,5,1,2,3],
'output': 3}
}
for test in test0:
print(count_rotations(test0['input']['nums']) == test0['input']['output'])
if you have any queries ask me for further clarification.
CodePudding user response:
def count_rotations(nums):
pass
test0 = {
'input': {
'nums': [4,5,1,2,3]
},
'output': 3
}
print(count_rotations(test0['input']['nums']) == test0['output'])
output:-
False
your for loop is looping twice.so, just remove the for loop and correct the print statement indentation according to it. then you'll be good to go.