[PYTHON] 07. Sentence generation by template

07. Sentence generation by template

Implement a function that takes arguments x, y, z and returns the string "y at x is z". Furthermore, set x = 12, y = "temperature", z = 22.4, and check the execution result.

Go

package main

import "fmt"

func template(x,y,z string) string {
	return fmt.Sprintf("%s time%s is%s",x,y,z)
}

func main() {
	fmt.Println(template("12","temperature","22.4"))
}

python

# -*- coding: utf-8 -*-

def template(x,y,z):
    return '{0}of time{1}Is{2}'.format(x,y,z)

print template(12,"temperature",22.4)

Javascript

function template(x,y,z) {
    return "y at x is z".replace("x",x).replace("y",y).replace("z",z);
}

console.log(template(12,"temperature",22.4));

Summary

Is this all right? ..

Top

Recommended Posts

07. Sentence generation by template
Collage template automatic generation
Template matching by OpenCV (CUDA)
Sentence generation with GRU (keras)
Prime number generation program by Python
Random number generation summary by Numpy
[PyTorch] Japanese sentence generation using Transformer
I tried sentence generation with GPT-2
template
Feature generation with pandas group by