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

Postby MrSweet1991 » Sun Jul 14, 2013 7:24 pm

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 Py110
import turtle

print 'The available places to select from are: '

print 'Birmingham, Coventry, West Bromwich: '

Place1, Place2, Place3 = 50,40,30


First = raw_input('Please select from the list where you are coming from: ')

Second = raw_input('Please select where you are going to: ')


distance = First + Second

print('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.
Reason: Added code tags
MrSweet1991
 
Posts: 2
Joined: Sun Jul 14, 2013 7:18 pm

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

Postby stranac » Sun Jul 14, 2013 8:41 pm

Read the topic titled New Users, Read This and edit your post.
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.
Reason: Added url
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1118
Joined: Thu Feb 07, 2013 3:42 pm

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

Postby ochichinyezaboombwa » Sun Jul 14, 2013 11:06 pm

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: 200
Joined: Tue Jun 04, 2013 7:53 pm

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

Postby Yoriz » Mon Jul 15, 2013 12:08 am

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'

ochichinyezaboombwa Your Fired :P
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 782
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

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

Postby ochichinyezaboombwa » Mon Jul 15, 2013 12:48 am

@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: 200
Joined: Tue Jun 04, 2013 7:53 pm

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

Postby Yoriz » Mon Jul 15, 2013 12:59 am

@ ochichinyezaboombwa: You missed the humour ;) .
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 782
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

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

Postby MrSweet1991 » Mon Jul 15, 2013 2:43 pm

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


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 4 guests