Python Forum
Frustrated with Assignment. S.O.S! HELP!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Frustrated with Assignment. S.O.S! HELP!
#8
(Nov-17-2019, 12:36 AM)Than999 Wrote: So the "verify" function is suppose to verify and "pass" or "fail" any given string list in the format of '####-####-####', based on four rules.

So the function should return 'pass' or 'fail' for give string, not the compliance to specific rule?

>>> def verify(string):  
...     digits = ''.join(char for char in string if char.isdigit())  
...     first_rule = digits[0] == '4' 
...     second_rule = int(digits[3]) - int(digits[4]) == 1 
...     third_rule = sum(int(num) for num in digits) % 4 == 0 
...     fourth_rule = int(digits[:2]) +  int(digits[6:8]) == 100 
...     if all([first_rule, second_rule, third_rule, fourth_rule]): 
...         return 'pass' 
...     else: 
...         return 'fail' 
...                                                                                       
>>> verify('4094-3460-2754')                                                              
'pass'
>>> verify('4084-3460-2754')                                                              
'fail'
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: Frustrated with Assignment. S.O.S! HELP! - by perfringo - Nov-19-2019, 06:42 AM
return in my function - by Than999 - Nov-17-2019, 08:32 PM
RE: return in my function - by perfringo - Nov-18-2019, 10:37 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020