CS50 Check for "Go back to Bank" doesn't approve of my code, even though the pytest test_bank.py does #64669
Replies: 3 comments 3 replies
-
@Seine242 Maybe you are facing these issues, I have mentioned. also, I have written code for you if the below code works please mark this answer as correct thanks. Version Differences: If you're using a different version of Python than the one used by CS50's check50, there might be subtle differences in behavior, especially if there were updates or changes between Python versions. Working Directory: The working directory might be different when the code is executed by check50. Make sure that the file paths in your code are specified correctly and consistently. Imports and Module Paths: Check that the way you're importing the value function from the bank module is compatible with the way check50 sets up the test environment. Dependencies: The issue could be related to the dependencies or libraries that are required by your code. If you're using any third-party libraries, make sure they are available in the CS50 environment. Whitespace and Indentation: Ensure that your code indentation and whitespace are consistent. Python is sensitive to indentation, and even small differences can lead to unexpected behavior. `# bank.py def value(greeting): def main(): if name == "main": `# test_bank.py from bank import value def test_int(): def test_blank(): def test_space(): def test_0(): def test_20(): def test_100(): def test_punct(): |
Beta Was this translation helpful? Give feedback.
-
In test_bank.py, change the return values from str to int(Ex: from '20' to 20) and update bank.py accordingly. For, the last line of 'Hints' section says "Take care to return, not print, an int in value." |
Beta Was this translation helpful? Give feedback.
-
Your convert function needs to return an integer value not a string. In your code, you are returning a string and still formatting it in main. |
Beta Was this translation helpful? Give feedback.
-
Body
I wrote the code for 'Bank' in CS50 course problem set 1, and CS50 check says that it is fully correct, as well as when I run test_bank.py both codes seem to be correct ( my output for running 'test_bank.py' is '7 PASSED'). However when I run the CS50 check 'check50 cs50/problems/2022/python/tests/bank' it outputs 4 error messages:
( test_bank.py exist
Log
checking that test_bank.py exists...
:( correct bank.py passes all test_bank checks
Cause
expected exit code 0, not 2
Log
running pytest test_bank.py...
checking that program exited with status 0...
:| test_bank catches bank.py with incorrect values
Cause
can't check until a frown turns upside down
:| test_bank catches bank.py without case-insensitivity
Cause
can't check until a frown turns upside down
:| test_bank catches bank.py not allowing for entire phrase
Cause
can't check until a frown turns upside down):
bank.py:
def main():
greeting = str(input("Greeting: "))
print('$' + value(greeting))
def value(greeting):
hello_list = (greeting.lower()).strip().split(' ')
if 'hello' in hello_list[0]:
return "0"
elif (greeting.strip())[0].lower() == "h" and not('hello' in hello_list[0].lower()):
return "20"
else:
return "100"
if name == "main":
main()
test_bank.py:
from bank import value
import pytest
def test_int():
assert value('1') == '100'
def test_blank():
with pytest.raises(IndexError):
value('')
def test_space():
with pytest.raises(IndexError):
value(' ')
def test_0():
assert value('Hello, how"s going?') == '0'
assert value('HELLO') == '0'
def test_20():
assert value('h') == '20'
assert value('hey, good') == '20'
assert value('HOLA ') == '20'
def test_100():
assert value('wow, hello') == '100'
assert value('LalhalHa') == '100'
def test_punct():
assert value(' .,;: "') == '100'
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions