#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    5
    Rep Power
    0

    AttributeError: 'module' object has no attribute 'randit'


    Hi,
    The following code keeps giving me a syntax error message for the if statement and the else statement. I am really not sure why. Can anyone provide some insight? Thanks.


    Here is the error message
    Traceback (most recent call last):
    File "C:\Python33\random_test.py", line 30, in <module>
    main()
    File "C:\Python33\random_test.py", line 8, in main
    number1 = random.randit(1,150)
    AttributeError: 'module' object has no attribute 'randit'
    >>>

    #This program displays the sum of two randomly generated numbers.

    import random

    def main():
    for count in range(1):
    #get two random numbers
    number1 = random.randit(1,300)
    number2 = random.randit(1,300)

    #Display the number.
    print(number1, number2)

    #Get result of both numbers
    combnumbers = number1 + number2

    #user input
    guessnumber = float(input('Enter sum of two numbers'))


    #display congratulation message
    if guessnumber == combnumbers
    print('Congratulations, You have the correct answer!')

    else:
    guessnumber != combnumbers
    print ('You did not enter correct answer')
    print ('The correct answer is', combnumbers)

    main()
    Last edited by hannahcorbin1 : Today at 10:27 PM. Reason: AttributeError: 'module' object has no attribute 'randit'
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Joensuu, Finland
    Posts
    436
    Rep Power
    67
    It’s “randint”.
    My armada: openSUSE 13.1 (home desktop, home laptop), Crunchbang Linux 11 (work laptop), Trisquel GNU/Linux 6.0.1 (mini laptop), Ubuntu 14.04 LTS (server), Android 4.2.1 (tablet), Windows 7 Ultimate (testbed)
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,855
    Rep Power
    481
    You could check the documentation for the functions in the random module, or you could

    >>> import random
    >>> dir(random) # randit isn't there!


    >>> help(random.randrange)


    you need a colon following the condition on the if statement.
    Code:
        if guessnumber == combnumbers:################
            print('Congratulations, You have the correct answer!')
        else:
            guessnumber != combnumbers  # this statement has no value other than wasting some microseconds.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo