## Creating a list to choose from then calculating the answers

This is the place for queries that don't fit in any of the other categories.

### Creating a list to choose from then calculating the answers

Hi All,

I'm running into a bit of trouble, I'm trying to create a list of places for the user to select from. The choices have distances assigned to them, I then want to get the first and second choices from the user and add the distances together, however it will only allow me to output as a string, whereas in this code I have chosen to output as an integer but I just get an error saying it can't do that. Here is the code I am trying to use, the code may look a little odd and that may be because we have to use a library that was created by one of our tutors.

Code: Select all
`import Py110import turtleprint 'The available places to select from are: 'print 'Birmingham, Coventry, West Bromwich: 'Place1, Place2, Place3 = 50,40,30First = raw_input('Please select from the list where you are coming from: ')Second = raw_input('Please select where you are going to: ')distance = First + Secondprint('the distance between the two places are' +int(distance))`
Last edited by Yoriz on Sun Jul 14, 2013 8:45 pm, edited 1 time in total.
MrSweet1991

Posts: 2
Joined: Sun Jul 14, 2013 7:18 pm

### Re: Creating a list to choose from then calculating the answ

Pay special attention to the parts about code tags and tracebacks.
Last edited by Yoriz on Sun Jul 14, 2013 8:46 pm, edited 2 times in total.
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: Creating a list to choose from then calculating the answ

Try to write a simpler program:
Code: Select all
`x = "Birmingham" + "Coventry"print (x)print (int(x))`
If you don't get it, fire your tutor and hire another one.
ochichinyezaboombwa

Posts: 203
Joined: Tue Jun 04, 2013 7:53 pm

### Re: Creating a list to choose from then calculating the answ

ochichinyezaboombwa wrote:Try to write a simpler program:
Code: Select all
`x = "Birmingham" + "Coventry"print (x)print (int(x))`
If you don't get it, fire your tutor and hire another one.

Code: Select all
`print (int(x))ValueError: invalid literal for int() with base 10: 'BirminghamCoventry'`

Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

Yoriz

Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

### Re: Creating a list to choose from then calculating the answ

@Yoriz: you missed the point. I wrote exactly what was the OP doing but much shorter, that was for the OP -- not you -- to try it and understand what the problem is.
ochichinyezaboombwa

Posts: 203
Joined: Tue Jun 04, 2013 7:53 pm

### Re: Creating a list to choose from then calculating the answ

@ ochichinyezaboombwa: You missed the humour .
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

Yoriz

Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

### Re: Creating a list to choose from then calculating the answ

ochichinyezaboombwa wrote:@Yoriz: you missed the point. I wrote exactly what was the OP doing but much shorter, that was for the OP -- not you -- to try it and understand what the problem is.

Hi Yoriz,

After looking at your code it seems clear except my variable needs to contain a strong linked to an integer (city to a given distance". My task states that this must be accomplished by... "using two dimensional arrays/lists to make matrices. First of all the demonstration will involve creating a matrix to represent distances between cities in miles, along with an array of strings which can be used to look up which city corresponds to which row. The user should then be able to look up the distances"

Any ideas how to code it to correspond with the above?
MrSweet1991

Posts: 2
Joined: Sun Jul 14, 2013 7:18 pm

### Who is online

Users browsing this forum: Bing [Bot] and 11 guests