Date: 18 July, 2023
Model: gpt-3.5-turbo
Temperature: 0.2
Passing runs: 0
Total runs: 10
Success rate: 0%
Tokens: 195
def check_dict_case(dict):
"""
Given a dictionary, return True if all keys are strings in lower
case or all keys are strings in upper case, else return False.
The function should return False is the given dictionary is empty.
Examples:
check_dict_case({"a":"apple", "b":"banana"}) should return True.
check_dict_case({"a":"apple", "A":"banana", "B":"banana"}) should return False.
check_dict_case({"a":"apple", 8:"banana", "a":"apple"}) should return False.
check_dict_case({"Name":"John", "Age":"36", "City":"Houston"}) should return False.
check_dict_case({"STATE":"NC", "ZIP":"12345" }) should return True.
"""
The above is an incomplete Python code fragment. Return the complete and correct code with no additional text.
def check_dict_case(dict):
"""
Given a dictionary, return True if all keys are strings in lower
case or all keys are strings in upper case, else return False.
The function should return False is the given dictionary is empty.
Examples:
check_dict_case({"a":"apple", "b":"banana"}) should return True.
check_dict_case({"a":"apple", "A":"banana", "B":"banana"}) should return False.
check_dict_case({"a":"apple", 8:"banana", "a":"apple"}) should return False.
check_dict_case({"Name":"John", "Age":"36", "City":"Houston"}) should return False.
check_dict_case({"STATE":"NC", "ZIP":"12345" }) should return True.
"""if len(dict.keys()) == 0:
return False
else:
state = "start"
for key in dict.keys():
if isinstance(key, str) == False:
state = "mixed"
break
if state == "start":
if key.isupper():
state = "upper"
elif key.islower():
state = "lower"
else:
break
elif (state == "upper" and not key.isupper()) or (state == "lower" and not key.islower()):
state = "mixed"
break
else:
break
return state == "upper" or state == "lower"
def check(candidate):
# Check some simple cases
assert candidate({"p":"pineapple", "b":"banana"}) == True, "First test error: " + str(candidate({"p":"pineapple", "b":"banana"}))
assert candidate({"p":"pineapple", "A":"banana", "B":"banana"}) == False, "Second test error: " + str(candidate({"p":"pineapple", "A":"banana", "B":"banana"}))
assert candidate({"p":"pineapple", 5:"banana", "a":"apple"}) == False, "Third test error: " + str(candidate({"p":"pineapple", 5:"banana", "a":"apple"}))
assert candidate({"Name":"John", "Age":"36", "City":"Houston"}) == False, "Fourth test error: " + str(candidate({"Name":"John", "Age":"36", "City":"Houston"}))
assert candidate({"STATE":"NC", "ZIP":"12345" }) == True, "Fifth test error: " + str(candidate({"STATE":"NC", "ZIP":"12345" }))
assert candidate({"fruit":"Orange", "taste":"Sweet" }) == True, "Fourth test error: " + str(candidate({"fruit":"Orange", "taste":"Sweet" }))
# Check some edge cases that are easy to work out by hand.
assert candidate({}) == False, "1st edge test error: " + str(candidate({}))
Start time: 2023-07-18 17:13:41
Duration: 9.47s
Completion tokens: 249
Result: Fail
def check_dict_case(dict):
"""
Given a dictionary, return True if all keys are strings in lower
case or all keys are strings in upper case, else return False.
The function should return False is the given dictionary is empty.
Examples:
check_dict_case({"a":"apple", "b":"banana"}) should return True.
check_dict_case({"a":"apple", "A":"banana", "B":"banana"}) should return False.
check_dict_case({"a":"apple", 8:"banana", "a":"apple"}) should return False.
check_dict_case({"Name":"John", "Age":"36", "City":"Houston"}) should return False.
check_dict_case({"STATE":"NC", "ZIP":"12345" }) should return True.
"""
if len(dict) == 0:
return False
keys = list(dict.keys())
first_key = keys[0]
if first_key.islower():
for key in keys:
if not key.islower():
return False
elif first_key.isupper():
for key in keys:
if not key.isupper():
return False
else:
return False
return True
Start time: 2023-07-18 17:13:37
Duration: 4.2s
Completion tokens: 92
Result: Fail
def check_dict_case(dict):
if len(dict) == 0:
return False
keys = list(dict.keys())
first_key = keys[0]
if first_key.islower():
for key in keys:
if not key.islower():
return False
elif first_key.isupper():
for key in keys:
if not key.isupper():
return False
else:
return False
return True
Start time: 2023-07-18 17:13:33
Duration: 3.6s
Completion tokens: 93
Result: Fail
def check_dict_case(dict):
if len(dict) == 0:
return False
keys = list(dict.keys())
first_key = keys[0]
if first_key.islower():
for key in keys:
if not key.islower():
return False
elif first_key.isupper():
for key in keys:
if not key.isupper():
return False
else:
return False
return True
Start time: 2023-07-18 17:13:29
Duration: 3.86s
Completion tokens: 97
Result: Fail
def check_dict_case(dict):
if len(dict) == 0:
return False
keys = list(dict.keys())
first_key = keys[0]
if first_key.islower():
for key in keys:
if not key.islower():
return False
elif first_key.isupper():
for key in keys:
if not key.isupper():
return False
else:
return False
return True
Start time: 2023-07-18 17:13:25
Duration: 4.14s
Completion tokens: 96
Result: Fail
def check_dict_case(dict):
if len(dict) == 0:
return False
keys = list(dict.keys())
first_key = keys[0]
if first_key.islower():
for key in keys:
if not key.islower():
return False
elif first_key.isupper():
for key in keys:
if not key.isupper():
return False
else:
return False
return True
Start time: 2023-07-18 17:13:21
Duration: 3.56s
Completion tokens: 92
Result: Fail
def check_dict_case(dict):
if len(dict) == 0:
return False
keys = list(dict.keys())
first_key = keys[0]
if first_key.islower():
for key in keys:
if not key.islower():
return False
elif first_key.isupper():
for key in keys:
if not key.isupper():
return False
else:
return False
return True
Start time: 2023-07-18 17:13:17
Duration: 3.7s
Completion tokens: 92
Result: Fail
def check_dict_case(dict):
if len(dict) == 0:
return False
keys = list(dict.keys())
first_key = keys[0]
if first_key.islower():
for key in keys:
if not key.islower():
return False
elif first_key.isupper():
for key in keys:
if not key.isupper():
return False
else:
return False
return True
Start time: 2023-07-18 17:13:13
Duration: 4.02s
Completion tokens: 92
Result: Fail
def check_dict_case(dict):
if len(dict) == 0:
return False
keys = list(dict.keys())
first_key = keys[0]
if first_key.islower():
for key in keys:
if not key.islower():
return False
elif first_key.isupper():
for key in keys:
if not key.isupper():
return False
else:
return False
return True
Start time: 2023-07-18 17:13:09
Duration: 4.16s
Completion tokens: 92
Result: Fail
def check_dict_case(dict):
if len(dict) == 0:
return False
keys = list(dict.keys())
first_key = keys[0]
if first_key.islower():
for key in keys:
if not key.islower():
return False
elif first_key.isupper():
for key in keys:
if not key.isupper():
return False
else:
return False
return True
Start time: 2023-07-18 17:12:59
Duration: 9.1s
Completion tokens: 249
Result: Fail
def check_dict_case(dict):
"""
Given a dictionary, return True if all keys are strings in lower
case or all keys are strings in upper case, else return False.
The function should return False is the given dictionary is empty.
Examples:
check_dict_case({"a":"apple", "b":"banana"}) should return True.
check_dict_case({"a":"apple", "A":"banana", "B":"banana"}) should return False.
check_dict_case({"a":"apple", 8:"banana", "a":"apple"}) should return False.
check_dict_case({"Name":"John", "Age":"36", "City":"Houston"}) should return False.
check_dict_case({"STATE":"NC", "ZIP":"12345" }) should return True.
"""
if len(dict) == 0:
return False
keys = list(dict.keys())
first_key = keys[0]
if first_key.islower():
for key in keys:
if not key.islower():
return False
elif first_key.isupper():
for key in keys:
if not key.isupper():
return False
else:
return False
return True