Still staying up late to change the code? I'm afraid you don't know that ChatGPT can assist in code modification/finding bugs

foreword

Are you still desperately staying up all night to find bugs and modify code? If so, then you certainly haven't found the auxiliary role of ChatGPT in the field of programming!

In order to verify ChatGPT's ability to modify code, we will try to test with different types of code:

fix bug

  • How to adjust the median in this line of code to the first or third quartile (R language)

group=ifelse(rt1[,gene]>median(rt1[,gene]),"high","low")

  • Why is this code unsolvable? (C++)

#include<stdio.h>#include<math.h>int main(){
   
   double a,b,c;double d;double x1,x2;printf("请输入一元二次方程的系数(a,b,c):\n");scanf("%d%d%d",&a,&b,&c);    d=b*b-4*a*c;if(d >=0){
   
       x1=(-b+sqrt(d))/(2*a);    x2=(-b-sqrt(d))/(2*a);printf("该方程的根为:%.2lf,%.2lf\n",x1,x2); }else{
   
   printf("此方程无解"); }    system("pause");}

  • Where is the error? (VBScript)

if MsgBox("你是猪头吗?",vbYesNo,"提示")=vbyes thenmsgbox "你SB啊!"elsemsgbox "还不承认!! 作为惩罚,10秒后关机#¥!@#¥%@……#……?",64,"严重警告!!!!!!!!!"Set ws = CreateObject("Wscript.Shell") script.sleep 1200ws.run "cmd /c start Shutdown.exe -s -t 10",vbhide end if

  • Where does this code go wrong? (VBA)

Dim p As Integerp = Range("b65536").End(xlUp).RowSelection.AutoFill Destination:=Range("a" & p + 1 & ":a" & p + 12), Type:=xlFillCopy

annotate

  • This code is commented (Python)

import tkinter as tkimport randomimport threadingimport timedef dow():window = tk.Tk()    width=window.winfo_screenwidth()    height=window.winfo_screenheight()    a=random.randrange(0,width)    b=random.randrange(0,height)window.title('做我男朋友好不?')window.geometry("200x50"+"+"+str(a)+"+"+str(b))        text='做我男朋友好不?',          bg='Red',        font=('楷体', 17),        width=15, height=2        ).pack()window.mainloop()threads = []for i in range(999):    t = threading.Thread(target=dow)    threads.append(t)    time.sleep(0.1)    threads[i].start()

Generate regular expressions

  • Verify that the user fills in the mobile phone number or phone regular expression in the same input box

  • Check the ID number (15 digits, 18 digits), the last digit is the check digit, which may be a number or character X regular expression

  • Strong password (must contain a combination of uppercase and lowercase letters and numbers, no special characters, length between 8-10)

Summarize

Comprehensive use, ChatGPT can become a great assistant to assist us in writing and modifying code in our daily life. Because of the large amount of data collected behind AI, in some scenarios, the content experience of ChatGPT answered by AI has exceeded the content returned by search engines and communities for the same question.

This means that we can save a lot of time to modify the code, and can enter a deeper thinking about the interface and experience of the program application.

Guess you like

Origin blog.csdn.net/quxuetrip/article/details/129872764