Date: 18 July, 2023
Model: gpt-4
Temperature: 0.2
Passing runs: 10
Total runs: 10
Success rate: 100%
Tokens: 133
def solve(s):
"""You are given a string s.
if s[i] is a letter, reverse its case from lower to upper or vise versa,
otherwise keep it as it is.
If the string contains no letters, reverse the string.
The function should return the resulted string.
Examples
solve("1234") = "4321"
solve("ab") = "AB"
solve("#a@C") = "#A@c"
"""
The above is an incomplete Python code fragment. Return the complete and correct code with no additional text.
def solve(s):
"""You are given a string s.
if s[i] is a letter, reverse its case from lower to upper or vise versa,
otherwise keep it as it is.
If the string contains no letters, reverse the string.
The function should return the resulted string.
Examples
solve("1234") = "4321"
solve("ab") = "AB"
solve("#a@C") = "#A@c"
"""flg = 0
idx = 0
new_str = list(s)
for i in s:
if i.isalpha():
new_str[idx] = i.swapcase()
flg = 1
idx += 1
s = ""
for i in new_str:
s += i
if flg == 0:
return s[len(s)::-1]
return s
def check(candidate):
# Check some simple cases
assert candidate("AsDf") == "aSdF"
assert candidate("1234") == "4321"
assert candidate("ab") == "AB"
assert candidate("#a@C") == "#A@c"
assert candidate("#AsdfW^45") == "#aSDFw^45"
assert candidate("#6@2") == "2@6#"
# Check some edge cases that are easy to work out by hand.
assert candidate("#$a^D") == "#$A^d"
assert candidate("#ccc") == "#CCC"
# Don't remove this line:
Start time: 2023-07-18 17:44:25
Duration: 3.61s
Completion tokens: 51
Result: Pass
def solve(s):
if not any(c.isalpha() for c in s):
return s[::-1]
else:
return ''.join(c.lower() if c.isupper() else c.upper() for c in s)
Start time: 2023-07-18 17:44:19
Duration: 5.27s
Completion tokens: 51
Result: Pass
def solve(s):
if not any(c.isalpha() for c in s):
return s[::-1]
else:
return ''.join(c.lower() if c.isupper() else c.upper() for c in s)
Start time: 2023-07-18 17:44:15
Duration: 3.9s
Completion tokens: 51
Result: Pass
def solve(s):
if not any(char.isalpha() for char in s):
return s[::-1]
else:
return ''.join(char.lower() if char.isupper() else char.upper() for char in s)
Start time: 2023-07-18 17:44:11
Duration: 3.95s
Completion tokens: 51
Result: Pass
def solve(s):
if not any(char.isalpha() for char in s):
return s[::-1]
else:
return ''.join(char.lower() if char.isupper() else char.upper() for char in s)
Start time: 2023-07-18 17:44:07
Duration: 4.64s
Completion tokens: 50
Result: Pass
def solve(s):
if any(char.isalpha() for char in s):
return ''.join(char.lower() if char.isupper() else char.upper() for char in s)
else:
return s[::-1]
Start time: 2023-07-18 17:44:03
Duration: 3.89s
Completion tokens: 51
Result: Pass
def solve(s):
if not any(c.isalpha() for c in s):
return s[::-1]
else:
return ''.join(c.lower() if c.isupper() else c.upper() for c in s)
Start time: 2023-07-18 17:43:59
Duration: 3.86s
Completion tokens: 50
Result: Pass
def solve(s):
if any(c.isalpha() for c in s):
return ''.join(c.upper() if c.islower() else c.lower() for c in s)
else:
return s[::-1]
Start time: 2023-07-18 17:43:53
Duration: 5.57s
Completion tokens: 51
Result: Pass
def solve(s):
if not any(c.isalpha() for c in s):
return s[::-1]
else:
return ''.join(c.lower() if c.isupper() else c.upper() for c in s)
Start time: 2023-07-18 17:43:47
Duration: 5.69s
Completion tokens: 50
Result: Pass
def solve(s):
if any(c.isalpha() for c in s):
return ''.join(c.lower() if c.isupper() else c.upper() for c in s)
else:
return s[::-1]
Start time: 2023-07-18 17:43:42
Duration: 5.51s
Completion tokens: 50
Result: Pass
def solve(s):
if any(c.isalpha() for c in s):
return ''.join(c.lower() if c.isupper() else c.upper() for c in s)
else:
return s[::-1]