How do i Multiply non-int by 'str'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Morgz123
    New Member
    • Jul 2008
    • 2

    How do i Multiply non-int by 'str'

    Okay Well i'm kinda new here
    First Post xD

    Well i recently entered in an online programming contest and i has since finished the question i went extremly badly on was when they wanted a program that wanted to make a google whackblatt, I wouldn't be able to explain what it is but i know how i though i should do it.

    It wanted me to make a program that asked for a string to repeat then how many times to repeat it. I think i have tried everything but they won't multiply

    Here's the code i used:

    resp=raw_input ("What is the string to repeat?" )
    times=raw_input ("How many times?")
    finished=resp*n ame
    print finished

    and the error message is:

    What is the string to repeat?test
    How many times?3

    Traceback (most recent call last):
    File "C:/Python25/Googlewhackblat ts2.py", line 3, in <module>
    finished=resp*n ame
    NameError: name 'name' is not defined


    Thanks xD

    PS I'm kinda new at programming so step by step instructions would be a help.
  • Benny the Guard
    New Member
    • Jun 2007
    • 92

    #2
    Two issues I see are:

    1. The variable name does not exist, the variable you mean is times
    2. raw_input returns a string, so you need to either cast it to an int with int (times) or just use the input method in place of raw_input. Should return an int.

    Good luck on the problem, you seem to be close.

    Comment

    • Morgz123
      New Member
      • Jul 2008
      • 2

      #3
      Originally posted by Benny the Guard
      Two issues I see are:

      1. The variable name does not exist, the variable you mean is times
      2. raw_input returns a string, so you need to either cast it to an int with int (times) or just use the input method in place of raw_input. Should return an int.

      Good luck on the problem, you seem to be close.
      Firstly thanks i understand what you mean a little but only a litte.

      Would you be able to redit my script so i may see what exactly you mean.

      My problem is i'm to impatient to just read absolutely everything i need so therefore i'm learning as i go along which means i encounter problems like these.

      Thanks

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        Originally posted by Morgz123
        Firstly thanks i understand what you mean a little but only a litte.

        Would you be able to redit my script so i may see what exactly you mean.

        My problem is i'm to impatient to just read absolutely everything i need so therefore i'm learning as i go along which means i encounter problems like these.

        Thanks
        resp=raw_input ("What is the string to repeat?" )
        times=raw_input ("How many times?")
        finished=resp*int(times)
        print finished

        Comment

        Working...