#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; February 21st, 2013 at 09:27 PM. Reason: AttributeError: 'module' object has no attribute 'randit'
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Iran
    Posts
    148
    Rep Power
    139
    Hi

    You misspelled the function name. It is randint and not randit
    Code:
    >>> import random
    >>> 
    >>> random.randint(100, 300)
    167
    >>> random.randit(100, 300)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute 'randit'
    >>>
    Also you have to add ":" at the end of the if statement
    Code:
    if guessnumber == combnumbers
    which becomes
    Code:
    if guessnumber == combnumbers:
    For future reference use code tags for those who read your programme and want to understand your problem. It makes the programme much more readable.


    Regards,
    Dariyoosh
    Last edited by dariyoosh; February 22nd, 2013 at 03:03 AM.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Iran
    Posts
    148
    Rep Power
    139
    Besides, why do you create two threads for the same problem?

    http://forums.devshed.com/python-programming-11/attributeerror-module-object-has-no-attribute-randit-940414.html

IMN logo majestic logo threadwatch logo seochat tools logo