Nov-27-2016, 03:29 PM
Hi all!
I just started learning python3.
I usually don't come to forums for help cause I'm a "do it your self" kinda a guy :D
This one has been breaking my balls over 4h now :/
"Create a program which reads all of the lines from the file and tests the lines. If the line has only letters and/or numbers, the program prints "[line] was ok.". If the line has special characters, the program should print "[line] was invalid.". When the program works, it prints out something like this:"
strings.txt contains the following:
Brb in 30min, need to go inhale some fresh air
ah forgot to post this, @ top
@wavic
In my lessons i havent gotten far enough to use "import"
iv gone through: if,else,break,skip,while,for,skip,write,read
I just started learning python3.
I usually don't come to forums for help cause I'm a "do it your self" kinda a guy :D
This one has been breaking my balls over 4h now :/
"Create a program which reads all of the lines from the file and tests the lines. If the line has only letters and/or numbers, the program prints "[line] was ok.". If the line has special characters, the program should print "[line] was invalid.". When the program works, it prints out something like this:"
>>> 5345m345ö34l was ok. no2no123non4 was ok. noq234n5ioqw#% was invalid. %#""SGMSGSER was invalid. doghdp5234 was ok. sg,dermoepm was invalid. 43453-frgsd was invalid. hsth())) was invalid. bmepm35wae was ok. vmopaem2234+0+ was invalid. gsdm12313 was ok. bbrbwb55be3"?"#? was invalid. "?"#%#"!%#"&"?%%"?#?#"?" was invalid. retrte#%#?% was invalid. abcdefghijklmnopqrstuvxy was ok. >>>this is what i got right now.
f = open("strings.txt") line = f.readline() for line in f: if "@"or "#" or "$" or "%" in line[0]: print(line," was invalid.") else: print(line," was ok.")
strings.txt contains the following:
Quote:5345m345ö34l .
no2no123non4
noq234n5ioqw#%
%#""SGMSGSER
doghdp5234
sg,dermoepm
43453-frgsd
hsth()))
bmepm35wae
vmopaem2234+0+
gsdm12313
bbrbwb55be3"?"#?
"?"#%#"!%#"&"?%%"?#?#"?"
retrte#%#?%
abcdefghijklmnopqrstuvxy
Brb in 30min, need to go inhale some fresh air

ah forgot to post this, @ top
Quote:"It is advisable to read the lines one at a time, test them with the isalmun() string test and go on from there. Also remember that the strings may also end in a line break (\n), which is allowed, but fails the .isalnum() test if not sliced away."
@wavic
In my lessons i havent gotten far enough to use "import"
iv gone through: if,else,break,skip,while,for,skip,write,read