AI Prompt Practice

 1.AI Based Program Generator 


Output:

Hello! I'd be happy to act as your AI programming assistant.

To get started, please provide me with the following two inputs:

  1. Problem Statement ({prob}): What specific task or problem do you want the program to solve?

  2. Programming Language ({prog}): Which programming language should I use to write the code?

Once I have those, I will generate the solution with the following sections: Problem Statement, Algorithm, Code, and Explanation.

Sample Input:

prob addition of two numbers ,prog python

Here is the program for the addition of two numbers in Python.

Problem Statement ➕

Write a program that takes two numerical inputs from the user and calculates their sum (addition).


Algorithm 💡

  1. Start: Begin the program.

  2. Input: Ask the user to enter the first number and store it in a variable (e.g., num1).

  3. Input: Ask the user to enter the second number and store it in a variable (e.g., num2).

  4. Process: Calculate the sum of num1 and num2. Store the result in a new variable (e.g., sum_result).

  5. Output: Display the calculated sum_result to the user.

  6. End: Terminate the program.


Code 💻

# The program uses the input() function to get values from the user.
# The float() function is used to convert the input (which is text by default)
# into a number that can handle both integers and decimals.

# 1. Get the first number from the user
num1 = float(input("Enter the first number: "))

# 2. Get the second number from the user
num2 = float(input("Enter the second number: "))

# 3. Calculate the sum
sum_result = num1 + num2

# 4. Display the result
print(f"The sum of {num1} and {num2} is: {sum_result}")

Explanation 📝

  1. num1 = float(input("Enter the first number: ")):

    • input(...) prompts the user with the message and waits for them to type a value. The value is received as a string (text).

    • float(...) converts the received string into a floating-point number (a number with or without a decimal), which allows the program to handle numbers like 5, 10.5, or -3.

    • The converted number is stored in the variable num1.

  2. num2 = float(input("Enter the second number: ")): This step does the exact same thing as step 1, but for the second number, storing it in num2.

  3. sum_result = num1 + num2: This is the core calculation. The + operator adds the numeric values stored in num1 and num2, and the result is saved in the sum_result variable.

  4. print(f"..."): This displays the final output to the user. An f-string (starting with f) is used to easily embed the values of the variables (num1, num2, and sum_result) directly within the text message.

Post a Comment

0 Comments

Close Menu