Slide 14
Slide 14 text
| © 2023 Cloud Ace, Inc
🤖異なる言語内でのコード変換(Python→Go)
package main
import (
"fmt"
"time"
)
func calculateDaysUntilDoraemonSBirthday() {
// Get today's date.
currentDate := time.Now()
fmt.Println("Today's date is", currentDate.Format("2006-01-02"))
// Get Doraemon's birthday.
birthday := time.Date(2112, 9, 3, 0, 0, 0, 0, time.UTC)
fmt.Println("Doraemon's birthday is", birthday.Format("2006-01-02"))
// Find the difference between today's date and Doraemon's birthday.
difference := birthday.Sub(currentDate)
// Print the number of days until Doraemon's birthday.
fmt.Println("There are", difference.Hours()/24, "days until Doraemon's birthday")
}
func main() {
calculateDaysUntilDoraemonSBirthday()
}
def calculate_days_until_doraemon_s_birthday():
"""Calculates and outputs the number of days until Doraemon's birthday.
Doraemon's birthday is September 3, 2112.
Uses the datetime module to get today's date.
Uses the timedelta module to find the difference between two dates.
The difference between two dates is the number of days.
"""
# Get today's date.
current_date = datetime.now()
print("Today's date is", current_date.strftime("%Y-%m-%d"))
# Get Doraemon's birthday.
birthday = datetime(2112, 9, 3)
print("Doraemon's birthday is", birthday.strftime("%Y-%m-%d"))
# Find the difference between today's date and Doraemon's birthday.
difference = birthday - current_date
# Print the number of days until Doraemon's birthday.
print("There are", difference.days, "days until Doraemon's birthday")
if __name__ == "__main__":
calculate_days_until_doraemon_s_birthday()
Python Go
コード変換後に動作しなかったが、チャット
ベースでトラブルシューティングを実施し、
その後正常に動作
※トラブルシューティング後のコード