mercredi 18 avril 2018

Python 3.6, Random Missing Randit Error Message:

I created a small guessing game,. However, no matter how hard I try I can't seem to figure out the issue with my script. The error message is: AttributeError: module 'random' has no attribute 'randit', could you help me figure out what's wrong. I am very confused about it.

import random
#User is the name of the person which is found with the input command below
user=input('What is your name?:')
#Number Computer Will Use:

fortysix=random.randit(1,1001)
numanswer=int(fortysix)
#Saying Hi
print('Hello',user)

#Input For Yes Or No
answer=input('\nWant to play a game? Yes or No?:')

#Determining if the user wants to proceed or not. So far you can only say                     
Yes with a capital y and not anything else.
if (answer=='Yes') :
    print('Great! Lets Begin!')
    print('\nLet\'s play a guessing game!')
    print('\nRules: I will think of a number between 1 and 100, you will         type in what number you think I am thinking of I will give you clues until you can figure it out! Let\'s begin!')


    #If you want to exit:
    exit=input('If you want to leave this game type in exit with no caps, if         you don\'t want to leave type no:')
    if (exit=='exit') :
        print('See you later!')
        import sys
        sys.exit()
    else :
        print('Good to know you\'ll be staying :),let\'s begin!')

    #Guessing
        num=int(input('\nWhat is your first guess? Type it in:'))
        if num > int('100') :
            print('That number is larger than 100,the number I choose is between 1 to 100, try again.')
            num=int(input('What is your second guess? Type it in:'))
        elif num==numanswer :
            print('Congratulations! You have figured out my number',user,'! Way to go!')
            import sys
            sys.exit()
        else :
            if num < numanswer :
                print('My number is larger than,',num,',try again.')
            elif num > numanswer :
                print('My number is smaller than,',num,',try again.')

            while num!=numanswer :
                num=int(input('\nWhat is your guess? Type it in:'))
            if num > int('100') :
                print('That number is larger than 100,the number I choose is between 1 to 100, try again.')
                num=int(input('What is your second guess? Type it in:'))
            elif num==numanswer :
                print('Congratulations! You have figured out my number',user,'! Way to go!')
                game=input('Would you like to use my dicitionary? Yes Or No?:')
                if game=='Yes' :
                    print('Great, starting dictionary script...')
                    pass #Add future dictionary script to this script 

                else :
                    print('Okay, see you later!')
                    import sys
                    sys.exit()
            else :
                if num < numanswer :
                    print('My number is larger than,',num,',try again.')
                elif num > numanswer :
                    print('My number is smaller than,',num,',try again.')

import random
#User is the name of the person which is found with the input command below
user=input('What is your name?:')
#Number Computer Will Use:

fortysix=random.randit(1,1001)
numanswer=int(fortysix)
#Saying Hi
print('Hello',user)

#Input For Yes Or No
answer=input('\nWant to play a game? Yes or No?:')

#Determining if the user wants to proceed or not. So far you can only say                     
    #Yes with a capital y and not anything else.
if (answer=='Yes') :
    print('Great! Lets Begin!')
    print('\nLet\'s play a guessing game!')
    print('\nRules: I will think of a number between 1 and 100, you will         type in what number you think I am thinking of I will give you clues until you can figure it out! Let\'s begin!')


    #If you want to exit:
    exit=input('If you want to leave this game type in exit with no caps, if         you don\'t want to leave type no:')
    if (exit=='exit') :
        print('See you later!')
        import sys
        sys.exit()
    else :
        print('Good to know you\'ll be staying :),let\'s begin!')

    #Guessing
        num=int(input('\nWhat is your first guess? Type it in:'))
        if num > int('100') :
            print('That number is larger than 100,the number I choose is between 1 to 100, try again.')
            num=int(input('What is your second guess? Type it in:'))
        elif num==numanswer :
            print('Congratulations! You have figured out my number',user,'! Way to go!')
            import sys
            sys.exit()
        else :
            if num < numanswer :
                print('My number is larger than,',num,',try again.')
            elif num > numanswer :
                print('My number is smaller than,',num,',try again.')

            while num!=numanswer :
                num=int(input('\nWhat is your guess? Type it in:'))
            if num > int('100') :
                print('That number is larger than 100,the number I choose is between 1 to 100, try again.')
                num=int(input('What is your second guess? Type it in:'))
            elif num==numanswer :
                print('Congratulations! You have figured out my number',user,'! Way to go!')
                game=input('Would you like to use my dicitionary? Yes Or No?:')
                if game=='Yes' :
                    print('Great, starting dictionary script...')
                    pass #Add future dictionary script to this script 

                else :
                    print('Okay, see you later!')
                    import sys
                    sys.exit()
            else :
                if num < numanswer :
                    print('My number is larger than,',num,',try again.')
                elif num > numanswer :
                    print('My number is smaller than,',num,',try again.')
else :
    print('See you later! Bye,')

I had a lot of indents in my code, and I had to turn all those indents into 4 spaces to allow the code into this question. Hopefully I didn't mess up any indents. Also, I know there are parts of my code that could be improved,but keep in mind this is an old script. I made a new version of this script, but it still has the same problem. This script used to work fine, I have no idea why it's not working now.




Aucun commentaire:

Enregistrer un commentaire