0% found this document useful (0 votes)
21 views

Simulation transcript_Generate code using IBM watsonx Prompt Lab

Uploaded by

freefactsff
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Simulation transcript_Generate code using IBM watsonx Prompt Lab

Uploaded by

freefactsff
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Use Generative AI for Software Development

Generate code using IBM watsonx

Task 1: Write new code using a prompt


In this task, you need to create a Python program that asks for your name and prints a greeting "Hello,
[your name]!".

• Utilize the example set up in IBM watsonx Prompt Lab for generating Python code.

• Write a relevant input prompt and generate the code.

The Code pad provides all the input text you’ll need to complete the task. Type the input exactly as it is
displayed in the Code pad.

Select the field to start typing. When you finish typing the command, press Enter.

Select the Next arrow to continue.

1. Ensure that the AI model codellama-34b-instruct-hf is selected and the Prompt Lab is set up
to generate Python code.

Select the Next arrow to continue.

Answer the question


You need to create a Python program that asks for your name and prints a greeting "Hello, [your name]!".

Which of the following is the best prompt to create this Python program?

Create a Python program that asks for my name and prints a greeting with it. After I enter my name,
the program should display "Hello, [my name]!"

Create a Python program that asks for my name and prints "Hello" followed by my name.

Create a Python program that asks for a name and prints "Hi, [name]!" after I enter it.

Create a Python program that asks for your name and prints a welcome message with your name.

2. Type the input prompt exactly as it is displayed in the Code pad.

Then, press Enter.

Code pad code:


# Create a Python program that asks for my name and prints a greeting with
it. After I enter my name, the program should display "Hello, [my name]!"

3. Select the Generate button.


4. Observe the Python code generated in the Output area.

Select the Next arrow to continue.

1
Use Generative AI for Software Development

Task 2: Convert existing code to another language


In this task, you need to convert the Python code into Hyper Text Markup Language (HTML). Python code
requires a special environment to run. However, an HTML page can be run like a web page in a browser.
This will allow you to see your code working.

• Set up in IBM watsonx Prompt Lab for converting Python code to another language.

• Write a relevant input prompt and convert the code.

The Code pad provides all the input text you’ll need to complete the task. Type the input exactly as it is
displayed in the Code pad.

Select the field to start typing. When you finish typing the command, press Enter.

Select the Next arrow to continue.

5. Set up the AI by typing the instruction exactly as it is displayed in the Code pad.

Then, press Enter.

Code pad code:


Translate the following code from Python to an HTML page to be run as a web
page in a browser.

6. Remove the example by selecting the cross (). This example is not relevant for translation of code.

7. Observe that the Examples section is now blank.

You do not have an example prompt and its output for converting Python code to HTML. So, leave it
blank and select the Next arrow to continue.

8. Copy and paste the input prompt from the Code pad.

Then, select the Next arrow to continue.

Code pad code:


# Convert the Python code here that asks for my name and prints a greeting
with it.
# After I enter my name, the program should display "Hello, [my name]!"

name = input("What is your name?")


print("Hello, " + name + "!")

9. Select the Generate button.

10. Observe the HTML code generated in the Output area.

Select the Next arrow to continue.

2
Use Generative AI for Software Development

Task 3: Run the HTML code in a browser


In this task, you will run the AI-generated code to check if it is working as expected.

• Copy the code to a “.html” file and save it.

• Run the HTML file in a browser.

The Code pad provides all the input text you’ll need to complete the task. Type the input exactly as it is
displayed in the Code pad.

Select the field to start typing. When you finish typing the command, press Enter.

Select the Next arrow to continue.

11. Copy the AI-generated code from the Code pad and paste in the file GreetByName.html.

Then, select the Next arrow to continue.

Code pad code:


<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
</head>
<body>
<script>
var name = prompt("What is your name?");
alert("Hello, " + name + "!");
</script>
</body>
</html>

12. Type the file location “D:\MyProject\GreetByName.html” in the address bar to view the file in
the browser.

Copy the location exactly from the Code pad.

Then, press Enter.

Code pad code:


D:\MyProject\GreetByName.html

13. Type your name in the text box.

Then, select the OK button.

14. Observe the greeting displayed. The AI-generated HTML code is working as expected.

Select the Next arrow to continue.

3
Use Generative AI for Software Development

Conclusion
You have successfully generated code using prompts in IBM watsonx Prompt Lab.

You might also like