mercredi 5 août 2020

Python - Return problem with random.randint()

import random

print("""
___  ___          _           ___  ____           _ 
|  \/  |         | |          |  \/  (_)         | |
| .  . | __ _ ___| |_ ___ _ __| .  . |_ _ __   __| |
| |\/| |/ _` / __| __/ _ \ '__| |\/| | | '_ \ / _` |
| |  | | (_| \__ \ ||  __/ |  | |  | | | | | | (_| |
\_|  |_/\__,_|___/\__\___|_|  \_|  |_/_|_| |_|\__,_|

                                                    """)

meno = input("""
    Ahoj nový hráč. 
    Pre pokračovanie zadaj svoje meno: """)

print("""
    Ahoj {}
    Pravidlá sú následovné. ja si myslím číslo a ty budeš hádať.
    Ak chceš ukončiť hru, napíš 'KONIEC'.
    Na konci hry uvidíš svoje skóre.""".format(meno))

print("\nMyslím si číslo")

random = random.randint(1,11)
guess = -1
good = 0
bad = 0
alltry = 0
while True:
    guess = input("Tvoj typ: ").strip().lower()
    alltry += 1
    if guess == "koniec":
        alltry -= 1
        print("\n+{:=^30}+".format("KONIEC"))
        print("|{:^15}|{:^14}|".format("Správne", good))
        print("|{:^15}|{:^14}|".format("Nesprávne", bad))
        print("|{:^15}|{:^14}|".format("Spolu", alltry))
        print("+{:=^30}+".format(""))
        print("\nĎakujem za hru {}\n".format(meno))
        break
    if guess == "":
        print("NEZADAL SI CISLO!")
    elif int(guess) == random:
        good += 1
        print("Máš to!!!")
        random = random.randint(1,11)
        guess = -1
    elif int(guess) < 1 or int(guess) > 10:
        print("ZADÁVAJ ČÍSLA IBA Z INTERVALU OD 1 PO 10!")
    elif guess != random:
        print("NESPRÁVNE!\nHádaj znovu.")
        guess = -1
        bad += 1

Hi I have problem with this code. It is game MasterMind. If guess number, program return problem.

Traceback (most recent call last): File "mastermind.py", line 47, in random = random.randint(1,11). AttributeError: 'int' object has no attribute 'randint'

Thanks for all help.




Aucun commentaire:

Enregistrer un commentaire