如何用ChatGPT设计出可控制的代码?古代最奇葩的昏君,让妃子躺在桌上与大臣共赏,从此诞生一个成语

【编者按】如何训练 ChatGPT 实现自己想要的代码与功能,秘诀就是编写更具交互性和前瞻性的设计提示,本文作者分享了如何利用 ChatGPT 设计出可控制的代码步骤。

原文链接:https://www.friendlyskies.net/maybe/a-quick-way-to-get-more-creative-coding-control-with-chatgpt

未经允许,禁止转载!

作者 | Marc Carson 译者 | 弯月出品 | CSDN(ID:CSDNnews)

你想通过 ChatGPT 更好地控制代码的实现吗?你希望 ChatGPT 的使用更加有趣,或者进一步激发灵感吗?

如果你的答案是肯定,请尝试使用更具交互性、前瞻性的设计提示,它可以提供各种想法,比如下面这个例子(粗体是我想强调的部分):Write a bash script with three functions: Allow a user to select how many dice to roll, roll the dice, and announce the results graphically. For each function, allow me to pick from three different ways of creating the function.编写一个 bash 脚本,其中包含三个功能:允许用户选择掷多少个骰子、掷骰子,并以图形方式宣布结果。对于每个函数,请提供三种不同的函数创建方式,让我从中进行选择。得到的代码如下:#!/bin/bash# Function 1: Allowing the user to select how many dice to roll# Option 1: Read input from userselect_dice_count_1() { read -p “Enter the number of dice to roll: “ dice_count echo $dice_count}# Option 2: Using command-line argumentsselect_dice_count_2() { dice_count=$1 echo $dice_count}# Option 3: Using a default valueselect_dice_count_3() { dice_count=1 echo $dice_count}# Function 2: Rolling the dice# Option 1: Using the $RANDOM variableroll_dice_1() { echo $((RANDOM % 6 + 1))}# Option 2: Using the shuf commandroll_dice_2() { shuf -i 1-6 -n 1}# Option 3: Using an array to represent the dice facesroll_dice_3() { dice_faces=(“1” “2” “3” “4” “5” “6”) index=$((RANDOM % 6)) echo ${dice_faces[$index]}}# Function 3: Announcing the results graphically# Option 1: Using a for loop and printfannounce_results_1() { for ((i = 1; i $1; i++)); do printf “[Dice $i] – $2\n” done}# Option 2: Using echo and a separator lineannounce_results_2() { for ((i = 1; i <= $1; i++)); do echo “Dice $i: $2 done echo “—————–“}# Option 3: Using ASCII art for graphical representationannounce_results_3() { for ((i = 1; i <= $1; i++)); do echo “╔═══╗” echo “║ $2 ║” echo “╚═══╝” done}# Main script# Selecting dice countdice_count=$(select_dice_count_1) # Change the function name to select_dice_count_2 or select_dice_count_3 for different options# Rolling the diceresults=“”for ((i = 1; i <= dice_count; i++)); do result=$(roll_dice_1) # Change the function name to roll_dice_2 or roll_dice_3 for different options results+=$resultdone# Announcing the resultsannounce_results_1 $dice_count $results # Change the function name to announce_results_2 or announce_results_3 for different options接下来,你只需要修改函数名称(ChatGPT 在注释中指出了这些位置)。你是否注意到,现在实际上你面临着软件设计问题,而不仅仅是“如何编写代码”的问题?这表明,使用 ChatGPT 编写代码的时候,你还可以进行一些设计,而不仅仅是简单地获取代码。不要止步于此随着创意源泉的涌现,你可以而且应该继续寻求更多有创意或有趣的想法。例如,后续的提示可以这么写:Give 3 more creative options for the display of the result.提供三个有创意的显示结果的方式。ChatGPT 生成的代码提供了如下三种方式:1)用点表示的 ASCII 骰子;2)ANSI 彩色骰子图形;3)表情符骰子。你还可以进一步,比如我要求 ChatGPT 给出三个更有创意的选项,然后它提供了一种播放掷骰子音效的方法,还有两种制作掷骰子动画的方法。看到音效选项,我非常惊讶,我不禁在想这是一个无聊的脚本,还是一个更具创意的有趣脚本?为设计增加一些灵活性这个简单的技巧可以给你提供更多方向性,以作者的身份控制脚本或程序的初始风格、感觉和功能。你可以快速审查各种不同的设计选择,更快地开发出更好的结果。此外,开发完成后,将来再修改会变得更加困难,主要受限于个人的记忆力和耐心,因此这种更具交互性的设计会更有优势。请注意,你需要根据脚本或编程的风格来修改代码。请务必利用 ChatGPT 可以使用的额外提示来指定你希望查看的代码类型的详细信息。ChatGPT 也可用于编程之外的工作这个技巧还可用于向 ChatGPT 询问与代码无关的技巧和其他查询。例如,在询问有关指定主题的技巧时,你可以添加如下内容:Present the tips in three different styles, only presenting the first tip of each style at first. Allow me to choose which style I like best before continuing with the rest of the tips.以三种不同的方式呈现技巧,首先呈现每种风格的第一个技巧。在显示后续技巧前,请允许我选择我最喜欢的风格。ChatGPT 的输出可以给你更多启发,让你更清楚地思考使用这些信息的方式。这意味着,在与 ChatGPT 合作设计的时候,你可以运用概念化技能,以获得更好的结果。你会发现,这样得到的结果更有创意。至少,不会感觉自己只是在做复制粘贴。总结和一些最终想法这种编写提示的小技巧不仅可以增加工作的乐趣,而且在我看来,还可以让你更好地了解 ChatGPT 的众多功能。大多数人在寻求编程方面的帮助时,只注重一个单一的“好”结果。但其实,在与 ChatGPT 交互时,注重拓宽思路,有利于获得更好的结果。

    THE END
    喜欢就支持一下吧
    点赞6 分享
    评论 抢沙发
    头像
    欢迎您留下宝贵的见解!
    提交
    头像

    昵称

    取消
    昵称表情代码图片

      暂无评论内容