- Maxxim
- Mar 10, 2007
-
You're overcome by an indescribably odd sensation...!
|
dis astranagant posted:
I'm still having trouble wrapping my head around how that's even supposed to work. The words all parse but I just can't make the logic happen.
code:( $ arg == 'B' ) ? 'bus' : ( $arg == 'A' ) => false
false ? 'airplane' : ( $arg == 'T' ) => true
true ? 'train' : ( $arg == 'C' ) => 'train'
'train' ? 'car' : ( $arg == 'H' ) => 'car'
'car' ? 'horse' : 'feet' => 'horse'
|
#
¿
Apr 10, 2012 20:23
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
May 10, 2024 20:42
|
|
- Maxxim
- Mar 10, 2007
-
You're overcome by an indescribably odd sensation...!
|
Using AI to write code is backwards since the AI is constantly evolving. The code will always be better tomorrow - you should stay up to date instead.
code:from openai import OpenAI
def is_even(value):
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
# optimization hack - ask it to return the values True or False so we can skip the cast
messages=[
{"role": "system", "content": "i need to know if a number is even. reply with only a single word with the same capitalization: True or False. reply True if the number is even, False otherwise."},
{"role": "user", "content": "is the following number even? " + str(value)}
]
)
return completion.choices[0].message.content
if __name__ == '__main__':
print(is_even(5))
print(is_even(-4412)) # test a negative number
print(is_even(100001)) # test a really big number
print(is_even(0))
code:> python is_even.py
False
True
False
True
|
#
¿
Mar 13, 2024 05:33
|
|