new to coding

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

new to coding

Postby danfan » Fri Oct 25, 2013 1:37 am

keep getting an error on elif, what am i doing wrong?

Code: Select all
varA = 2
varB = 1

if varB or varA == str:
 print("string involved")

elif
 if varA > varB:
  print('bigger')
   
elif
 if varA == varB:
  print('equal')
 
elif
 if varA < varB:   
  print('smaller')
Last edited by micseydel on Fri Oct 25, 2013 1:57 am, edited 1 time in total.
Reason: Code tags, lock.
danfan
 
Posts: 14
Joined: Fri Oct 25, 2013 1:33 am

Re: new to coding

Postby Mekire » Fri Oct 25, 2013 2:06 am

You are probably looking for something more like this:
Code: Select all
varA = 2
varB = 1

if isinstance(varB,str) or isinstance(varA,str):
    print("string involved")

elif varA > varB:
    print('bigger')

elif varA == varB:
    print('equal')

elif varA < varB:
    print('smaller')

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

Re: new to coding

Postby danfan » Fri Oct 25, 2013 2:13 am

here is where i am at now, have an error on line 14, I
I don't know what isinstance does, i have not gotten that far yet.

varA = 2
varB = 1

if varB or varA == str:
print("string involved")

elif varA > varB:
print('bigger')

elif varA == varB:
print('equal')

else varA < varB:
print('smaller')
danfan
 
Posts: 14
Joined: Fri Oct 25, 2013 1:33 am

Re: new to coding

Postby Yoriz » Fri Oct 25, 2013 5:26 am

Hi danfan,
Please read the 'new users read this' link in my signature then add code tags when you post any code and error tracebacks when you get errors.
You can look up isinstance in the documentation here is a link to it.
isinstance
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: 831
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: new to coding

Postby stranac » Fri Oct 25, 2013 7:41 am

If you just take a look at the course's forum(yes, I know which course you're taking), you would have seen this question answered many times before.

They are planning for you to use the type() function to check if any of the variable types is a string.
The isinstance function is just a better way of doing it.

Other than that, your elif and else syntax is broken.
An elif statement must have a condition, an else can not.
Friendship is magic!

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

Re: new to coding

Postby micseydel » Fri Oct 25, 2013 6:05 pm

stranac wrote:They are planning for you to use the type() function to check if any of the variable types is a string.
The isinstance function is just a better way of doing it.

Eww, I had it when people teach newbs bad habits D=
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: 1354
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: new to coding

Postby danfan » Sat Oct 26, 2013 3:11 am

I am dropping that course, I think it sucks, it took me an hour to figure it out.

anyone know of any good courses, I have found thenewboston tutorials on youtube and khanacademy, any good links? or any good books? I looking for a book that is written for normal people who are not a frikken genius.

p.s I HATE NUMBERS, I HATE MATH, are there any tutorials that don't use math to explain this stuff, i can't understand what is going on when there is Xs and Ys all over the place
danfan
 
Posts: 14
Joined: Fri Oct 25, 2013 1:33 am

Re: new to coding

Postby Crimson King » Sat Oct 26, 2013 7:37 am

danfan wrote:anyone know of any good courses, I have found thenewboston tutorials on youtube and khanacademy, any good links? or any good books? I looking for a book that is written for normal people who are not a frikken genius.


Check out this thread viewtopic.php?f=25&t=5063, there's plenty of resources there.

Have fun!
User avatar
Crimson King
 
Posts: 107
Joined: Fri Mar 08, 2013 2:42 pm
Location: Buenos Aires, Argentina

Re: new to coding

Postby Kebap » Sat Oct 26, 2013 10:36 am

danfan wrote:I HATE NUMBERS, I HATE MATH

Yeah well Logic and Programming kind of depend on that stuff.. better loosen your frikken prejudices :mrgreen:
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 396
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: new to coding

Postby danfan » Sun Oct 27, 2013 2:12 am

I tired a bunch of things in idle, it worked but won't work in this course ?

http://postimg.org/image/ff9z1ffnx/
danfan
 
Posts: 14
Joined: Fri Oct 25, 2013 1:33 am

Re: new to coding

Postby stranac » Sun Oct 27, 2013 2:40 am

That couldn't have worked in idle.

s.count('e' 'i' 'o' 'u') is the same as s.count('eiou')
That will count the number of times 'eiou' apears in s.

Also, 'a' is also a vowel.
Friendship is magic!

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


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests