REVscene Automotive Forum

REVscene Automotive Forum (https://www.revscene.net/forums/)
-   Campus Forum (https://www.revscene.net/forums/campus-forum_20/)
-   -   Anyone at SFU right now? (https://www.revscene.net/forums/541525-anyone-sfu-right-now.html)

CRS 02-28-2013 07:33 AM

So CMPT guys.... Python Gods.....

I'm trying to count the number of LETTERS/CHARACTERS in a string and not its numbers/special characters.

So in a string like "abc132add" it would count 6 (only the letters) any idea how to do this?

I'm not looking for a position thing because the strings can be different.

Messerschmitt 02-28-2013 07:42 AM

Look for asci characters and see which of them are the letters. Then if the asci is between that range, count it as a letter

CRS 02-28-2013 07:45 AM

Quote:

Originally Posted by Messerschmitt (Post 8172268)
Look for asci characters and see which of them are the letters. Then if the asci is between that range, count it as a letter

I think that's too advanced? I was going to do some variation of len(st) or st.count(abcd...).

But neither of those work....

:okay:

jtanner_ 02-28-2013 08:03 AM

Quote:

Originally Posted by CRS (Post 8172271)
I think that's too advanced? I was going to do some variation of len(st) or st.count(abcd...).

But neither of those work....

:okay:

Oh god it's been a long time since I took cmpt120... but can't you use isdigit and isalpha?

ex.

"a".isalpha() should return true, and "a".isdigit() should return false...

So after you define your input...

count=0
for char in input:
if isalpha(char):
count +=1
return count

:badpokerface:

Otherwise I think Messer is right in that you can use string.ascii too.. but I don't have python on this computer to play around with lol.

OpenRoadAutoGrp 02-28-2013 08:24 AM

Quote:

Originally Posted by bmwx1 (Post 8172224)
Lmao that face when you get up at 4am is what I'm experiencing right now. Are you the guy near the engineering building exit with the openroad promotion and that Scion FRS outside?

Yep! We're up there today as well with that autographed Burrows jersey prize.

CRS 02-28-2013 08:54 AM

Quote:

Originally Posted by jtanner_ (Post 8172283)
Oh god it's been a long time since I took cmpt120... but can't you use isdigit and isalpha?

ex.

"a".isalpha() should return true, and "a".isdigit() should return false...

So after you define your input...

count=0
for char in input:
if isalpha(char):
count +=1
return count

:badpokerface:

Otherwise I think Messer is right in that you can use string.ascii too.. but I don't have python on this computer to play around with lol.

No workie...

:(

Thanks though!

Anyone know any good cmpt tutors?

jtanner_ 02-28-2013 09:06 AM

Quote:

Originally Posted by CRS (Post 8172313)
No workie...

:(

Thanks though!

Anyone know any good cmpt tutors?

Really? What does it return? So fail...

Quote:

def main():
<I>sentence = input('Enter a sentence: ')
<I> Stats(sentence)

def Stats(input):
<I>print('Letters:', letter(input))

def letter(input):
<I>count=0
<I>for char in input:
<I><I> if isalpha(char):
<I><I><I> count += 1
<I> return count
Sorry... I tried installing python but I don't have administrator rights so it won't let me lol. Indents don't seem to show lol. where <I> represents an indent

ph0 02-28-2013 09:44 AM

Quote:

Originally Posted by CRS (Post 8172264)
So CMPT guys.... Python Gods.....

I'm trying to count the number of LETTERS/CHARACTERS in a string and not its numbers/special characters.

So in a string like "abc132add" it would count 6 (only the letters) any idea how to do this?

I'm not looking for a position thing because the strings can be different.

So here's a pseudocode I came up with for this:

alphabet = letters of alphabet (lowercase and uppercase)
intizalize count to 0
for letters in string //Check each character in string
if letters in alphabet //if character is in the alphabet than count + 1
count = count + 1
return count
Spoiler!

CRS 02-28-2013 10:12 AM

Thanks for the effort all.

Assignment closed already. I'll post up answers once they are received.

Geoc 02-28-2013 01:32 PM

Quote:

Originally Posted by jtanner_ (Post 8172321)
Really? What does it return? So fail...



Sorry... I tried installing python but I don't have administrator rights so it won't let me lol. Indents don't seem to show lol. where <I> represents an indent

problem with isalpha(char) is that it is supposed to be string.isalpha();, so you would need to do

for i in range 1 to len(string)
if string[i-1].isalpha()
count += 1;

vyrospec 02-28-2013 05:43 PM

wow so much comp sci support.

anyways: summer enrollment dates released
I got a March 15th 2:30

Geoc 02-28-2013 05:45 PM

Quote:

Originally Posted by vyrospec (Post 8172786)
wow so much comp sci support.

anyways: summer enrollment dates released
I got a March 15th 2:30

Used to be in bus, then realize it's a pointless degree unless you're in accounting.:fuckthatshit: So I switched to a BSc. degree

yray 02-28-2013 05:52 PM

Quote:

Originally Posted by vyrospec (Post 8172786)
wow so much comp sci support.

anyways: summer enrollment dates released
I got a March 15th 2:30

10:30:troll:

vyrospec 02-28-2013 05:54 PM

Quote:

Originally Posted by Geoc (Post 8172789)
Used to be in bus, then realize it's a pointless degree unless you're in accounting.:fuckthatshit: So I switched to a BSc. degree

you should join me in ECON :badpokerface::troll:

is350 02-28-2013 06:30 PM

Damn why are you guys so early? Mine is on the 21st. Is it because you guys are in 4th year, a lot of units accumulated, or high GPA?:badpokerface:

ph0 02-28-2013 06:31 PM

Mine's on the 25th LOL daymmmmm but going to vietnam this summer, so no summer semesterr :fullofwin:

BrRsn 02-28-2013 06:49 PM

Fuck

Ever take a class that is hard, miss a midterm, add weight to your final, and realize it's fucking hard?

I did. Final is worth 80%, midterm 20%
Will reply back with results :fuckthatshit:

Geoc 02-28-2013 07:00 PM

Quote:

Originally Posted by vyrospec (Post 8172799)
you should join me in ECON :badpokerface::troll:

I'm actually majoring in econ as well...:pokerface:

yray 02-28-2013 07:06 PM

Quote:

Originally Posted by bmwx1 (Post 8172830)
Damn why are you guys so early? Mine is on the 21st. Is it because you guys are in 4th year, a lot of units accumulated, or high GPA?:badpokerface:

it's cuz i failed too many courses

nma 02-28-2013 07:34 PM

anyone in econ 345 and/or 354? both midterms tomorrow..

:fuuuuu:

vyrospec 02-28-2013 07:45 PM

^ im in 345, how u preparing for it

nma 02-28-2013 07:47 PM

just trying to do practice exams to see how well i know the material, it gets kinda confusing to be honest I haven't been paying much attention in lecture lol

nma 02-28-2013 07:51 PM

Quote:

Originally Posted by yray (Post 8172797)
10:30:troll:

9:30 :troll::troll::troll:

vyrospec 02-28-2013 08:12 PM

Quote:

Originally Posted by nma (Post 8172916)
just trying to do practice exams to see how well i know the material, it gets kinda confusing to be honest I haven't been paying much attention in lecture lol

ya pretty much the same. did 3 mts over the weekend. now to finish 2 more practice that i missed out when downloading the stuff. im surprised at how well i did so far.

nma 02-28-2013 08:13 PM

it's not that bad I'm just screwed because I have two exams back to back tomorrow, all the information is kind of overwhelming lol


All times are GMT -8. The time now is 05:07 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
SEO by vBSEO ©2011, Crawlability, Inc.
Revscene.net cannot be held accountable for the actions of its members nor does the opinions of the members represent that of Revscene.net