recently started learning python from cs50p. facing issues in pset 5 problem 2 (back to the bank)
(it is supposed to remove vowels upon input) —> (code is given below as text)
my code for bank.py is running well and fine when i test it manually in the terminal but the test_bank.py doesnt seem to work when using pytest. the third case with others works but not the other two (hello and words with h)
i have made a lot of tweaks here and there but just cant seem to figure out whats wrong. so where have i went wrong? any help or correction in my code (if its wrong) would be appreciated..
(https://i.sstatic.net/MBVs62Ip.png) — this image is what i get after testing in terminal
code for bank.py is below-
def main():
userInput = input("Greeting: ").strip().lower()
output = value(userInput)
print (f"${output}")
def value(greeting):
if greeting.startswith("hello"):
return int(0)
elif greeting[0] == "h":
return int(20)
else:
return int(100)
if __name__ == "__main__":
main()
code for test_bank.py is below
from bank import value
def test_value_hello():
assert value("Hello, World!") == int(0)
assert value("hello there") == int(0)
def test_value_h():
assert value("Hey, World!") == int(20)
assert value("How are you doing?") == int(20)
def test_value_others():
assert value("What's up?") == 100
assert value("greetings!") == 100
Samast Rustagi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1