我肯定不是用这个呀,翻了好久才翻到了正宗的 GNU GCC ,他原本的 gcc 链接都被 xcode 覆盖了,要 gcc-9 才是他😂
1 2 3 4 5
[c@My-MacBook:] guess !551 $ g++-9 --version g++-9 (Homebrew GCC 9.2.0) 9.2.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the sourcefor copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
这个就肯定没问题了,编译运行:
正常解决方案
刚才那个代码有点怪,而且没做异常处理,再好好写一个。
这段时间都在用 Golang,所以今天写一个大家喜闻乐见的 Python3 版本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import random
if __name__ == "__main__": num = random.randint(0, 100) cnt = 0 print("猜测一个0到100之间的整数.") while cnt < 100: cnt += 1 try: inp = int(input(f"第 {cnt} 次猜,请输入一个整形数字: ")) if inp == num: print("恭喜你猜对了,这个数是 %d。" % num) exit(0) print("太大"if inp > num else"太小") except ValueError: print("输入无效,这次不算。") cnt -= 1 print("你怕不是个傻子!")