Simple Coding Help

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

Re: Simple Coding Help

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

yes, i tested with a pos, neg and 0.
User avatar
iixCarbonxZz
 
Posts: 15
Joined: Fri Nov 22, 2013 5:43 pm

Re: Simple Coding Help

Postby ochichinyezaboombwa » Sat Nov 23, 2013 3:11 am

Two comments:
a) try
Code: Select all
777 < "0"

b) read about if/elif/else.

1) if you have "if / if / if", there may be something wrong.
This was your original example with "Civic" etc.

2) if you have "if / elif / elif" but no "else" there also might be (and usually is) something terribly wrong (logically).
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm

Re: Simple Coding Help

Postby iixCarbonxZz » Sat Nov 23, 2013 8:24 am

oh i fixed it, all the problem was is that i hadn't heard of elif. Now I have expanded quite considerably.

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

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

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

elif car == ("Skyline"):
        sky = input("Please choose either R32, R33 or R34..." )

        if sky == ("R32"):
            print ("cool, I like those.")

        elif sky == ("R33"):
            print ("SIIK, those are good for Track Days.")

        elif sky == ("R34"):
            print ("BANG ON!, touge bawssing...")

elif car == ("Jaguar"):
        jag = input("Please choose either XF, XK or XKR...")

        if jag == ("XF"):
            print("They look excellent in white.")

        elif jag == ("XK"):
            print("ooh, The sporty one. Great for cruising the countryside.")

        elif jag ==("XKR"):
            print("nice, that one's great for showing off.")

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 iixCarbonxZz » Sat Nov 23, 2013 11:24 am

at the end, does anyone know how to repeat the process from this line of code:

Code: Select all
car = input("Please choose a car Manufacturer..." )
User avatar
iixCarbonxZz
 
Posts: 15
Joined: Fri Nov 22, 2013 5:43 pm

Re: Simple Coding Help

Postby Mekire » Sat Nov 23, 2013 3:33 pm

You would need to wrap the whole part you want to repeat in a while loop.

-Mek
User avatar
Mekire
 
Posts: 1149
Joined: Thu Feb 07, 2013 11:33 pm
Location: Asakusa, Japan

Re: Simple Coding Help

Postby iixCarbonxZz » Sat Nov 23, 2013 10:05 pm

Mekire wrote:You would need to wrap the whole part you want to repeat in a while loop.

-Mek


I don't think that you are wrong but i can't make it work. could you elaborate on where the loop would go using this as an example?

Code: Select all
car = input("Please choose a car Manufacturer..." )

if car ==("Integra"):
         print("nice...")

else:
    print ("I have nothing to say about any " + car + "s")
User avatar
iixCarbonxZz
 
Posts: 15
Joined: Fri Nov 22, 2013 5:43 pm

Re: Simple Coding Help

Postby ochichinyezaboombwa » Sat Nov 23, 2013 10:45 pm

Basically, you create an "infinite loop" with one exception: if a user is fed up you let her go.

Code: Select all
while True:
    car = input("Please choose a car Manufacturer..." )
    if car ==("Integra"):
         print("nice...")
    else:
        print ("I have nothing to say about any " + car + "s")

    yn = input("One more time?.." )
    if yn not in in ('Y', 'y'):
        print ("Thanks for playing!")
        break

-- something like this.
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm

Re: Simple Coding Help

Postby iixCarbonxZz » Sat Nov 23, 2013 11:23 pm

in line 9 it made me delete one of the INs and it kinda worked. what I mean is although it repeated, it didn't ask the question.
User avatar
iixCarbonxZz
 
Posts: 15
Joined: Fri Nov 22, 2013 5:43 pm

Re: Simple Coding Help

Postby iixCarbonxZz » Sat Nov 23, 2013 11:25 pm

nvm. i fixed it, it was to do with the indents.
User avatar
iixCarbonxZz
 
Posts: 15
Joined: Fri Nov 22, 2013 5:43 pm

Previous

Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], knightrider179 and 5 guests

cron