gpt4 book ai didi

go - 如何修复 Golang 中的 %!(EXTRA int=3) 错误?

转载 作者:行者123 更新时间:2023-12-01 21:17:57 25 4
gpt4 key购买 nike

我对 Golang 很陌生,我想知道为什么每次运行代码时都会出现这个错误
%!(EXTRA int=3)

...
var money int
var buyItem string
fmt.Print("Inserisci il nome dell'arma che vuoi comprare: ")
fmt.Scan(&buyItem)
switch buyItem {
case "Racchetta":
fmt.Println("Hai comprato con successo la racchetta")
money = money - 1
fmt.Printf("Soldi rimanenti:", money)
case "Granata":
fmt.Println("Hai comprato con successo la granata")
money = money - 7
fmt.Printf("Soldi rimanenti:", money)
case "AK":
fmt.Println("Hai comprato con successo l'AK")
money = money - 12
fmt.Printf("Soldi rimanenti:", money)
default:
fmt.Println("Non hai inserito il nome dell'arma corretto")
}

当我运行它时,我收到此错误:Soldi rimanenti:%!(EXTRA int=3)谁能帮我吗?

最佳答案

您需要向字符串添加格式化程序,例如

fmt.Printf("Soldi rimanenti: %v\n", money)

%v 是通用格式化程序,适用于大多数情况,但还有更多。在这里查看示例 https://gobyexample.com/string-formatting

\n 用于在打印后添加换行符。

关于go - 如何修复 Golang 中的 %!(EXTRA int=3) 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61425099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com