Simple Coding Help

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

Simple Coding Help

Postby iixCarbonxZz » Fri Nov 22, 2013 5:48 pm

I'm looking for some help with some help with some coding I'm doing for my Computer Science class at school.

In the attached picture you should find a copy of the coding and each individual objects outcome. I am hoping that you can see what I'm trying to do and help me to solve the problem.

http://imgur.com/eIcrSWZ

happy now...
Last edited by micseydel on Fri Nov 22, 2013 11:05 pm, edited 5 times in total.
Reason: Locked OP.
User avatar
iixCarbonxZz
 
Posts: 15
Joined: Fri Nov 22, 2013 5:43 pm

Re: Simple Coding Help

Postby micseydel » Fri Nov 22, 2013 7:45 pm

stranac modified your post with his comment rather than making a new one, and I'm not sure if you get an email or update about that, so I'm doing so. You can also upload your picture to imgur.com or something rather than embed it in this page, but include a warning if it's going to be larger than people expect.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1222
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Simple Coding Help

Postby Stauricus » Fri Nov 22, 2013 11:00 pm

i have no idea on what your problem is. your code seems to work as expected.
what are you trying to do?
Stauricus
 
Posts: 6
Joined: Mon Nov 18, 2013 3:35 pm

Re: Simple Coding Help

Postby micseydel » Fri Nov 22, 2013 11:07 pm

It looks like you need to unindent your later ifs.

What you're doing is
Code: Select all
if x == 1:
    if x == 2:
        print "x is equal to 1 and 2!"

which is never true.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1222
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Simple Coding Help

Postby stranac » Fri Nov 22, 2013 11:10 pm

iixCarbonxZz wrote:http://imgur.com/eIcrSWZ

happy now...

Of course not. That's not even close to what I told you to do.

Your code might be simple enough for people to help you even with how it is posted right now, but posting images of code just makes helping you harder.
If you post more complicated code like this, helping becomes impossible.
Better to post the right way from the start.
Friendship is magic!

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

Re: Simple Coding Help

Postby iixCarbonxZz » Sat Nov 23, 2013 12:13 am

so what you're saying is that you can't help me...is that it, is this your convoluted way of saying that???
Last edited by iixCarbonxZz on Sat Nov 23, 2013 12:18 am, edited 1 time in total.
User avatar
iixCarbonxZz
 
Posts: 15
Joined: Fri Nov 22, 2013 5:43 pm

Re: Simple Coding Help

Postby iixCarbonxZz » Sat Nov 23, 2013 12:16 am

Stauricus wrote:i have no idea on what your problem is. your code seems to work as expected.
what are you trying to do?



well the basic idea is that it is a user-input and when the input is equal to any of the if statements it prints the required message where as if it is something else it will just print the bottom-most message.
User avatar
iixCarbonxZz
 
Posts: 15
Joined: Fri Nov 22, 2013 5:43 pm

Re: Simple Coding Help

Postby stranac » Sat Nov 23, 2013 12:26 am

iixCarbonxZz wrote:so what you're saying is that you can't help me...is that it, is this your convoluted way of saying that???

No, I'm just trying to help you make better posts.

The solution to the coding problem you have was already given to you by micseydel.
Friendship is magic!

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

Re: Simple Coding Help

Postby iixCarbonxZz » Sat Nov 23, 2013 12:29 am

i would like to say it were that simple but for me it didn't work, if you can suggest a better way for me to 'present' the code to you
then be my guest but if you can't actually help me then just leave it.
User avatar
iixCarbonxZz
 
Posts: 15
Joined: Fri Nov 22, 2013 5:43 pm

Re: Simple Coding Help

Postby stranac » Sat Nov 23, 2013 12:32 am

I have suggested a better way, it was in the edit I made to your post.
It was to read the New Users, Read This topic, which explains what a post should look like.

Also, how did it not work for you?
What is it exactly you tried?
Friendship is magic!

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

Re: Simple Coding Help

Postby iixCarbonxZz » Sat Nov 23, 2013 12:35 am

Code: Select all
print ("THE CAR CHOOSER!!!")

while input == ():

    car = input("Please choose a car..." )
    car = (str(car)



    if car == ("Civic")
        print ("VTEC Just Kicked In Yo!!!")
   
    if car == ("Toureg"):
        print ("The full VW Toureg")

   
    if car == ("MK2 Golf"):
        print ("You Dubsta!")
break


    print ("Your choice of car was " + car)



did you mean like this?

oh yeh, missed that last bit. as he said un-indent the later ifs i assumed that meant to un-indent all but the first if statement.
User avatar
iixCarbonxZz
 
Posts: 15
Joined: Fri Nov 22, 2013 5:43 pm

Re: Simple Coding Help

Postby stranac » Sat Nov 23, 2013 12:44 am

Yes, that's how you should post your code.

Code: Select all
while input == ():

That makes no sense. I have no idea what you're trying there.
There's also a random break outside of any loops, which I guess you wanted to use in combinations with the while...

Code: Select all
car = (str(car)

You're missing a closing parenthesis here.
Also, input() already returns a string, so that str() is pointless.

If you get rid of this while stuff, and simply unindent the ifs in from your original code, it should work fine...
Friendship is magic!

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

Re: Simple Coding Help

Postby iixCarbonxZz » Sat Nov 23, 2013 12:50 am

the code runs again, thanks but it still doesn't solve my original problem.

looking back i didn't actually mention this i don't think. although the if statements work, they all end up coming up with the else statement at the bottom.
i want them to print their assigned messages and only them. if you can see what i mean.

i'm currently at this:

Code: Select all
print ("THE CAR CHOOSER!!!")
car = input("Please choose a car..." )

if car == ("Civic"):
        print ("VTEC Just Kicked In Yo!!!")
   
if car == ("Toureg"):
        print ("The full VW Toureg")

   
if car == ("MK2 Golf"):
        print ("You Dubsta!")


else:
    print ("Your choice of car was " + car)
User avatar
iixCarbonxZz
 
Posts: 15
Joined: Fri Nov 22, 2013 5:43 pm

Re: Simple Coding Help

Postby stranac » Sat Nov 23, 2013 12:55 am

That's really close, but you want to use if/elif/else here.
Code: Select all
if car == 'Civic':
    # do stuff
elif car == 'Toureg':
    # do stuff
elif car == 'MK2 Golf':
    # do stuff
else:
    # do the default
Friendship is magic!

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

Re: Simple Coding Help

Postby iixCarbonxZz » Sat Nov 23, 2013 12:58 am

thank you, this has worked.

sorry about being a little ignorant erlier, getting annoyed at it not working...
User avatar
iixCarbonxZz
 
Posts: 15
Joined: Fri Nov 22, 2013 5:43 pm

Re: Simple Coding Help

Postby stranac » Sat Nov 23, 2013 1:02 am

Glad you got it to work.

Also, please don't quote every post you're replying to.
It just makes following the conversation harder.

Only quote if you think it's needed for understanding what you're replying to.
Friendship is magic!

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

Re: Simple Coding Help

Postby iixCarbonxZz » Sat Nov 23, 2013 1:04 am

ok, i'l remember that.

elif works on so many levels, i added a whole other category inside one of the car types, thanks again. :D
User avatar
iixCarbonxZz
 
Posts: 15
Joined: Fri Nov 22, 2013 5:43 pm

Re: Simple Coding Help

Postby ochichinyezaboombwa » Sat Nov 23, 2013 1:06 am

Now that after a dozen unsuccessful posts you've finally posted some code in code tags: let me congratulate you! This is a huge breakthrough, and you finally deserve some help.

As for the problem in your snippet: you need to read more about the if / elif /else construct.
I'll explain some of it based on your code, but you should really read a tutorial, do a whole bunch of simple exercised, and only then .... you know.

Anyway:
if you enter "Civic", what happens?
1st, python does this:
Code: Select all
if car == ("Civic"):
    print ("VTEC Just Kicked In Yo!!!")
-- exactly as you directed it to do.
But then....
It goes on and evaluates:
a)
Code: Select all
if car == ("Toureg"): # nope, it's not : so nothing happens here


b)
Code: Select all
if car == ("MK2 Golf"): # nope, it's not : so nothing happens here


c)
Code: Select all
else: # yes, ELSE: IT's not MK2 Golf, it's still Civic!
#so the next line is executed:
    print ("Your choice of car was " + car)



My advice: right now, drop your program and write another one:
a) it asks a user to enter any number;
b) if a positive number entered, it says " positive",
c) if it's negative, it says: "negative";
d) if it's neither, it says "neither neg nor pos".

Can you do it quickly?
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm

Re: Simple Coding Help

Postby iixCarbonxZz » Sat Nov 23, 2013 1:17 am

quick enough?

Code: Select all
number = input("select a number...")

if number < "0":
    print ("your number is Negative")

elif number == "0":
    print ("your number is neither positive nor negative")

elif number > "0":
    print("your number is positive")
User avatar
iixCarbonxZz
 
Posts: 15
Joined: Fri Nov 22, 2013 5:43 pm

Re: Simple Coding Help

Postby ochichinyezaboombwa » Sat Nov 23, 2013 1:18 am

Yes, quick enough. Have you tried it? Does it work as expected? :-)
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm

Next

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 1 guest