By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,760 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,760 IT Pros & Developers. It's quick & easy.

How do i Multiply non-int by 'str'

P: 2
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*name
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/Googlewhackblatts2.py", line 3, in <module>
finished=resp*name
NameError: name 'name' is not defined


Thanks xD

PS I'm kinda new at programming so step by step instructions would be a help.
Jul 30 '08 #1
Share this Question
Share on Google+
3 Replies

P: 92
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.
Jul 30 '08 #2

P: 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.
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
Aug 1 '08 #3

bvdet
Expert Mod 2.5K+
P: 2,851
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
Aug 2 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.