“ ValueError:int()base必须为> = 2且<= 36或0”的错误消息为何?

时间:2019-01-26 01:51:27

标签: python-3.x

我正在制作一个基于文本的小游戏,您必须猜测介于某些标准之间的数字,该标准可以由用户或由随机数生成器预设,但是问题是当我尝试随机生成两个参数时游戏中出现错误“ ValueError:int()的基数必须> = 2且<= 36或0”

我实际上不知道应该尝试什么,因为我以前从未遇到过这个问题。

import random

Guess = 0
Run = ("Yes")
while Run == ("Yes"):
    Number_1 = random.randint(1, 30)
    Number_2 = random.randint(int(Number_1, 999999999999))
    Answer = random.randint(int(Number_1), int(Number_2))
    while int(Guess) != int(Answer):
        Guess = (input("\nWhat is your guess? > "))
        if int(Guess) < int(Answer):
            print("The answer is Greater then that.")
        if int(Guess) > int(Answer):
            print("The answer is less then that.")
        print("Congrates on guessing correctly!!")
        Again = (input("\nDo you want to play again? ('y' or 'n') > "))
        if Again == ("y"):
            Run = ("Yes")
        if Again == ("n"):
            Run = ("No")

我希望它会生成2个数字,分别是最低编号和最高编号,然后让用户尝试猜测该编号,但似乎无法正确生成该编号。

1 个答案:

答案 0 :(得分:0)

您在语句class ViewController:UIViewController, GADInterstitialDelegate { override func viewDidLoad() { super.viewDidLoad() interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910") interstitial.delegate = self let request = GADRequest() interstitial.load(request) } @IBAction func adButton(_ sender: UIButton) { if (interstitial.isReady) { interstitial.present(fromRootViewController: self) } else { self.present(myVC, animated: true, completion: nil) } } //Tells the delegate the interstitial is to be animated off the screen. func interstitialWillDismissScreen(_ ad: GADInterstitial) { print("interstitialWillDismissScreen") } //Tells the delegate the interstitial had been animated off the screen. func interstitialDidDismissScreen(_ ad: GADInterstitial) { print("interstitialDidDismissScreen") let storyboard = UIStoryboard(name: "Main", bundle: nil) let myVC = storyboard.instantiateViewController(withIdentifier: "newVC") self.present(myVC, animated: true, completion: nil) } } 中放置了一个结束括号,因此,您不是在要求Number_2 = random.randint(int(Number_1, 999999999999))和999999999999之间的随机整数,而是要系统将Number_1解析为以base-999999999999表示。