Problems with 'with open', to create a trivial challenge in python The Next CEO of Stack OverflowCalling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?How to get the current time in Python“Least Astonishment” and the Mutable Default ArgumentDoes Python have a string 'contains' substring method?Way to create multiline comments in Python?
Won the lottery - how do I keep the money?
Which one is the true statement?
Axiom Schema vs Axiom
Is it my responsibility to learn a new technology in my own time my employer wants to implement?
Chain wire methods together in Lightning Web Components
If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?
Can MTA send mail via a relay without being told so?
WOW air has ceased operation, can I get my tickets refunded?
Why is my new battery behaving weirdly?
Can a Bladesinger Wizard use Bladesong with a Hand Crossbow?
Why don't programming languages automatically manage the synchronous/asynchronous problem?
Is there a way to save my career from absolute disaster?
Why doesn't UK go for the same deal Japan has with EU to resolve Brexit?
How do I align (1) and (2)?
Powershell. How to parse gci Name?
I want to delete every two lines after 3rd lines in file contain very large number of lines :
Where do students learn to solve polynomial equations these days?
Grabbing quick drinks
Why this way of making earth uninhabitable in Interstellar?
Newlines in BSD sed vs gsed
Running a General Election and the European Elections together
Prepend last line of stdin to entire stdin
Is it professional to write unrelated content in an almost-empty email?
Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?
Problems with 'with open', to create a trivial challenge in python
The Next CEO of Stack OverflowCalling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?How to get the current time in Python“Least Astonishment” and the Mutable Default ArgumentDoes Python have a string 'contains' substring method?Way to create multiline comments in Python?
I would like create a trivial challenge ! But it's not working as I would. This is my code :
import os
with open('questions','r') as file:
l = 0
question = []
right_guess = []
wrong_guess_1 = []
wrong_guess_2 = []
for line in file:
content_line = []
for char in line:
content_line.append(char)
if l == 0:
question.append(content_line)
l = 1
elif l == 1:
right_guess.append(content_line)
l = 2
elif l == 2:
wrong_guess_1.append(content_line)
l = 3
elif l == 3:
wrong_guess_2.append(content_line)
l = 4
if l == 4:
break
print(question)
print(right_guess)
print(wrong_guess_1)
print(wrong_guess_2)
input('Awnser : ')
Ok, now let's me explain the two problems. I've try my code with this question file structure ( there is no extention, it's just 'question' ) :
a question
the right anwser
false guess
false guess
a other question
the right anwser
false guess
false guess
here a example, if you don't understand :
How does 1 + 1 ?
3
0
5
Obviously the answer is the second line : 3 ! ( just kidding, it's 2, I know :D )
So, let's back to our problem : I've start the code and it's give me this result :
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
Answer :
I don't really understand where is the problem but I hope someone will help me to get this result :
How does 1+1 ?
2
0
5
Answer
And if some of poeple who will watching this page are really crazy, I could expect have this result :
(the program take one question, randomly, in the whole file)
the chosen one
one of the three possibles guests
one other of the three possibles guests
a third possible guest
( And we don't know which one is the correct )
Answer :
I think this is all, thank to anyone who will try to give a clue, a element or who will contribute to this little program !
python python-3.x
|
show 5 more comments
I would like create a trivial challenge ! But it's not working as I would. This is my code :
import os
with open('questions','r') as file:
l = 0
question = []
right_guess = []
wrong_guess_1 = []
wrong_guess_2 = []
for line in file:
content_line = []
for char in line:
content_line.append(char)
if l == 0:
question.append(content_line)
l = 1
elif l == 1:
right_guess.append(content_line)
l = 2
elif l == 2:
wrong_guess_1.append(content_line)
l = 3
elif l == 3:
wrong_guess_2.append(content_line)
l = 4
if l == 4:
break
print(question)
print(right_guess)
print(wrong_guess_1)
print(wrong_guess_2)
input('Awnser : ')
Ok, now let's me explain the two problems. I've try my code with this question file structure ( there is no extention, it's just 'question' ) :
a question
the right anwser
false guess
false guess
a other question
the right anwser
false guess
false guess
here a example, if you don't understand :
How does 1 + 1 ?
3
0
5
Obviously the answer is the second line : 3 ! ( just kidding, it's 2, I know :D )
So, let's back to our problem : I've start the code and it's give me this result :
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
Answer :
I don't really understand where is the problem but I hope someone will help me to get this result :
How does 1+1 ?
2
0
5
Answer
And if some of poeple who will watching this page are really crazy, I could expect have this result :
(the program take one question, randomly, in the whole file)
the chosen one
one of the three possibles guests
one other of the three possibles guests
a third possible guest
( And we don't know which one is the correct )
Answer :
I think this is all, thank to anyone who will try to give a clue, a element or who will contribute to this little program !
python python-3.x
3
maybe look again at the number of equal signs in "if l = 4"
– Trilarion
Mar 7 at 16:09
4
Please show actual code. There are at least three typos in this code that would prevent it from running at all; so how can we know what is causing your issue?
– Daniel Roseman
Mar 7 at 16:10
1
But also ask yourself why you are iterating through every character in a line and appending it to a list, if that isn't what you want the output to be.
– Daniel Roseman
Mar 7 at 16:11
@trilarion, just a error of myselft, cause I've rewrite the whole program by hand ^^
– Edhyjox
Mar 7 at 16:12
1
FYI, the word is "guess", not "guest". A guest is a visitor.
– Barmar
Mar 7 at 16:13
|
show 5 more comments
I would like create a trivial challenge ! But it's not working as I would. This is my code :
import os
with open('questions','r') as file:
l = 0
question = []
right_guess = []
wrong_guess_1 = []
wrong_guess_2 = []
for line in file:
content_line = []
for char in line:
content_line.append(char)
if l == 0:
question.append(content_line)
l = 1
elif l == 1:
right_guess.append(content_line)
l = 2
elif l == 2:
wrong_guess_1.append(content_line)
l = 3
elif l == 3:
wrong_guess_2.append(content_line)
l = 4
if l == 4:
break
print(question)
print(right_guess)
print(wrong_guess_1)
print(wrong_guess_2)
input('Awnser : ')
Ok, now let's me explain the two problems. I've try my code with this question file structure ( there is no extention, it's just 'question' ) :
a question
the right anwser
false guess
false guess
a other question
the right anwser
false guess
false guess
here a example, if you don't understand :
How does 1 + 1 ?
3
0
5
Obviously the answer is the second line : 3 ! ( just kidding, it's 2, I know :D )
So, let's back to our problem : I've start the code and it's give me this result :
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
Answer :
I don't really understand where is the problem but I hope someone will help me to get this result :
How does 1+1 ?
2
0
5
Answer
And if some of poeple who will watching this page are really crazy, I could expect have this result :
(the program take one question, randomly, in the whole file)
the chosen one
one of the three possibles guests
one other of the three possibles guests
a third possible guest
( And we don't know which one is the correct )
Answer :
I think this is all, thank to anyone who will try to give a clue, a element or who will contribute to this little program !
python python-3.x
I would like create a trivial challenge ! But it's not working as I would. This is my code :
import os
with open('questions','r') as file:
l = 0
question = []
right_guess = []
wrong_guess_1 = []
wrong_guess_2 = []
for line in file:
content_line = []
for char in line:
content_line.append(char)
if l == 0:
question.append(content_line)
l = 1
elif l == 1:
right_guess.append(content_line)
l = 2
elif l == 2:
wrong_guess_1.append(content_line)
l = 3
elif l == 3:
wrong_guess_2.append(content_line)
l = 4
if l == 4:
break
print(question)
print(right_guess)
print(wrong_guess_1)
print(wrong_guess_2)
input('Awnser : ')
Ok, now let's me explain the two problems. I've try my code with this question file structure ( there is no extention, it's just 'question' ) :
a question
the right anwser
false guess
false guess
a other question
the right anwser
false guess
false guess
here a example, if you don't understand :
How does 1 + 1 ?
3
0
5
Obviously the answer is the second line : 3 ! ( just kidding, it's 2, I know :D )
So, let's back to our problem : I've start the code and it's give me this result :
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
[[ 'H', 'o', 'w', ' ', 'd', 'o', 'e', 's', ' ', '1', '+', '1', ' ', '?', 'n']]
Answer :
I don't really understand where is the problem but I hope someone will help me to get this result :
How does 1+1 ?
2
0
5
Answer
And if some of poeple who will watching this page are really crazy, I could expect have this result :
(the program take one question, randomly, in the whole file)
the chosen one
one of the three possibles guests
one other of the three possibles guests
a third possible guest
( And we don't know which one is the correct )
Answer :
I think this is all, thank to anyone who will try to give a clue, a element or who will contribute to this little program !
python python-3.x
python python-3.x
edited Mar 7 at 16:18
Edhyjox
asked Mar 7 at 16:04
EdhyjoxEdhyjox
5510
5510
3
maybe look again at the number of equal signs in "if l = 4"
– Trilarion
Mar 7 at 16:09
4
Please show actual code. There are at least three typos in this code that would prevent it from running at all; so how can we know what is causing your issue?
– Daniel Roseman
Mar 7 at 16:10
1
But also ask yourself why you are iterating through every character in a line and appending it to a list, if that isn't what you want the output to be.
– Daniel Roseman
Mar 7 at 16:11
@trilarion, just a error of myselft, cause I've rewrite the whole program by hand ^^
– Edhyjox
Mar 7 at 16:12
1
FYI, the word is "guess", not "guest". A guest is a visitor.
– Barmar
Mar 7 at 16:13
|
show 5 more comments
3
maybe look again at the number of equal signs in "if l = 4"
– Trilarion
Mar 7 at 16:09
4
Please show actual code. There are at least three typos in this code that would prevent it from running at all; so how can we know what is causing your issue?
– Daniel Roseman
Mar 7 at 16:10
1
But also ask yourself why you are iterating through every character in a line and appending it to a list, if that isn't what you want the output to be.
– Daniel Roseman
Mar 7 at 16:11
@trilarion, just a error of myselft, cause I've rewrite the whole program by hand ^^
– Edhyjox
Mar 7 at 16:12
1
FYI, the word is "guess", not "guest". A guest is a visitor.
– Barmar
Mar 7 at 16:13
3
3
maybe look again at the number of equal signs in "if l = 4"
– Trilarion
Mar 7 at 16:09
maybe look again at the number of equal signs in "if l = 4"
– Trilarion
Mar 7 at 16:09
4
4
Please show actual code. There are at least three typos in this code that would prevent it from running at all; so how can we know what is causing your issue?
– Daniel Roseman
Mar 7 at 16:10
Please show actual code. There are at least three typos in this code that would prevent it from running at all; so how can we know what is causing your issue?
– Daniel Roseman
Mar 7 at 16:10
1
1
But also ask yourself why you are iterating through every character in a line and appending it to a list, if that isn't what you want the output to be.
– Daniel Roseman
Mar 7 at 16:11
But also ask yourself why you are iterating through every character in a line and appending it to a list, if that isn't what you want the output to be.
– Daniel Roseman
Mar 7 at 16:11
@trilarion, just a error of myselft, cause I've rewrite the whole program by hand ^^
– Edhyjox
Mar 7 at 16:12
@trilarion, just a error of myselft, cause I've rewrite the whole program by hand ^^
– Edhyjox
Mar 7 at 16:12
1
1
FYI, the word is "guess", not "guest". A guest is a visitor.
– Barmar
Mar 7 at 16:13
FYI, the word is "guess", not "guest". A guest is a visitor.
– Barmar
Mar 7 at 16:13
|
show 5 more comments
3 Answers
3
active
oldest
votes
Your first problem is here:
content_line = []
for char in line:
content_line.append(char)
None of this is needed. Just use line
for the next few lines:
for line in file:
if l == 0:
question.append(line)
etc
add a comment |
The code in the question does not give the same line multiple times as an output. If that was an issue, it is not represented in this code.
The reason you're getting lists instead of strings as a result is that you're explicitly making those lists:
content_line = []
for char in line:
content_line.append(char)
If you simply used line
directly (or line.rstrip()
if you want to remove the newline at the end), you would get a line of text for each line in the file.
The reason you're getting lists inside of lists is that you're not only putting characters in a list, you're then appending those to another list. As it seems you only have one item per list, and that you expect a single string from printing the list, you could simply replace those lists by the strings.
Instead of appending to lists, just assign to the variables:
for line in file:
# Remove trailing whitespace at the end of the line
content_line = line.rstrip()
if l == 0:
question = content_line
l = 1
elif l == 1:
right_guess = content_line
l = 2
elif l == 2:
wrong_guess_1 = content_line
l = 3
elif l == 3:
wrong_guess_2 = content_line
l = 4
add a comment |
Ok, so this look to be the final code :
for line in file:
# Remove trailing whitespace at the end of the line
content_line = line.rstrip()
if l == 0:
question = content_line
l = 1
elif l == 1:
right_guess = content_line
l = 2
elif l == 2:
wrong_guess_1 = content_line
l = 3
elif l == 3:
wrong_guess_2 = content_line
l = 4
Thank you quamrana, user1018651 and anyone who ave put a comment to help me !
Anyway, It still a 'little' thing to fix and I think this is the hardest one :
Transform this code for add the random questions and get, at end, this :
(the program take one question, randomly, in the whole file)
the chosen one
one of the three possibles guests
one other of the three possibles guests
a third possible guest
( And we don't know which one is the correct )
Answer :
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55048118%2fproblems-with-with-open-to-create-a-trivial-challenge-in-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your first problem is here:
content_line = []
for char in line:
content_line.append(char)
None of this is needed. Just use line
for the next few lines:
for line in file:
if l == 0:
question.append(line)
etc
add a comment |
Your first problem is here:
content_line = []
for char in line:
content_line.append(char)
None of this is needed. Just use line
for the next few lines:
for line in file:
if l == 0:
question.append(line)
etc
add a comment |
Your first problem is here:
content_line = []
for char in line:
content_line.append(char)
None of this is needed. Just use line
for the next few lines:
for line in file:
if l == 0:
question.append(line)
etc
Your first problem is here:
content_line = []
for char in line:
content_line.append(char)
None of this is needed. Just use line
for the next few lines:
for line in file:
if l == 0:
question.append(line)
etc
answered Mar 7 at 16:13
quamranaquamrana
13.5k74054
13.5k74054
add a comment |
add a comment |
The code in the question does not give the same line multiple times as an output. If that was an issue, it is not represented in this code.
The reason you're getting lists instead of strings as a result is that you're explicitly making those lists:
content_line = []
for char in line:
content_line.append(char)
If you simply used line
directly (or line.rstrip()
if you want to remove the newline at the end), you would get a line of text for each line in the file.
The reason you're getting lists inside of lists is that you're not only putting characters in a list, you're then appending those to another list. As it seems you only have one item per list, and that you expect a single string from printing the list, you could simply replace those lists by the strings.
Instead of appending to lists, just assign to the variables:
for line in file:
# Remove trailing whitespace at the end of the line
content_line = line.rstrip()
if l == 0:
question = content_line
l = 1
elif l == 1:
right_guess = content_line
l = 2
elif l == 2:
wrong_guess_1 = content_line
l = 3
elif l == 3:
wrong_guess_2 = content_line
l = 4
add a comment |
The code in the question does not give the same line multiple times as an output. If that was an issue, it is not represented in this code.
The reason you're getting lists instead of strings as a result is that you're explicitly making those lists:
content_line = []
for char in line:
content_line.append(char)
If you simply used line
directly (or line.rstrip()
if you want to remove the newline at the end), you would get a line of text for each line in the file.
The reason you're getting lists inside of lists is that you're not only putting characters in a list, you're then appending those to another list. As it seems you only have one item per list, and that you expect a single string from printing the list, you could simply replace those lists by the strings.
Instead of appending to lists, just assign to the variables:
for line in file:
# Remove trailing whitespace at the end of the line
content_line = line.rstrip()
if l == 0:
question = content_line
l = 1
elif l == 1:
right_guess = content_line
l = 2
elif l == 2:
wrong_guess_1 = content_line
l = 3
elif l == 3:
wrong_guess_2 = content_line
l = 4
add a comment |
The code in the question does not give the same line multiple times as an output. If that was an issue, it is not represented in this code.
The reason you're getting lists instead of strings as a result is that you're explicitly making those lists:
content_line = []
for char in line:
content_line.append(char)
If you simply used line
directly (or line.rstrip()
if you want to remove the newline at the end), you would get a line of text for each line in the file.
The reason you're getting lists inside of lists is that you're not only putting characters in a list, you're then appending those to another list. As it seems you only have one item per list, and that you expect a single string from printing the list, you could simply replace those lists by the strings.
Instead of appending to lists, just assign to the variables:
for line in file:
# Remove trailing whitespace at the end of the line
content_line = line.rstrip()
if l == 0:
question = content_line
l = 1
elif l == 1:
right_guess = content_line
l = 2
elif l == 2:
wrong_guess_1 = content_line
l = 3
elif l == 3:
wrong_guess_2 = content_line
l = 4
The code in the question does not give the same line multiple times as an output. If that was an issue, it is not represented in this code.
The reason you're getting lists instead of strings as a result is that you're explicitly making those lists:
content_line = []
for char in line:
content_line.append(char)
If you simply used line
directly (or line.rstrip()
if you want to remove the newline at the end), you would get a line of text for each line in the file.
The reason you're getting lists inside of lists is that you're not only putting characters in a list, you're then appending those to another list. As it seems you only have one item per list, and that you expect a single string from printing the list, you could simply replace those lists by the strings.
Instead of appending to lists, just assign to the variables:
for line in file:
# Remove trailing whitespace at the end of the line
content_line = line.rstrip()
if l == 0:
question = content_line
l = 1
elif l == 1:
right_guess = content_line
l = 2
elif l == 2:
wrong_guess_1 = content_line
l = 3
elif l == 3:
wrong_guess_2 = content_line
l = 4
answered Mar 7 at 16:23
user10186512user10186512
1415
1415
add a comment |
add a comment |
Ok, so this look to be the final code :
for line in file:
# Remove trailing whitespace at the end of the line
content_line = line.rstrip()
if l == 0:
question = content_line
l = 1
elif l == 1:
right_guess = content_line
l = 2
elif l == 2:
wrong_guess_1 = content_line
l = 3
elif l == 3:
wrong_guess_2 = content_line
l = 4
Thank you quamrana, user1018651 and anyone who ave put a comment to help me !
Anyway, It still a 'little' thing to fix and I think this is the hardest one :
Transform this code for add the random questions and get, at end, this :
(the program take one question, randomly, in the whole file)
the chosen one
one of the three possibles guests
one other of the three possibles guests
a third possible guest
( And we don't know which one is the correct )
Answer :
add a comment |
Ok, so this look to be the final code :
for line in file:
# Remove trailing whitespace at the end of the line
content_line = line.rstrip()
if l == 0:
question = content_line
l = 1
elif l == 1:
right_guess = content_line
l = 2
elif l == 2:
wrong_guess_1 = content_line
l = 3
elif l == 3:
wrong_guess_2 = content_line
l = 4
Thank you quamrana, user1018651 and anyone who ave put a comment to help me !
Anyway, It still a 'little' thing to fix and I think this is the hardest one :
Transform this code for add the random questions and get, at end, this :
(the program take one question, randomly, in the whole file)
the chosen one
one of the three possibles guests
one other of the three possibles guests
a third possible guest
( And we don't know which one is the correct )
Answer :
add a comment |
Ok, so this look to be the final code :
for line in file:
# Remove trailing whitespace at the end of the line
content_line = line.rstrip()
if l == 0:
question = content_line
l = 1
elif l == 1:
right_guess = content_line
l = 2
elif l == 2:
wrong_guess_1 = content_line
l = 3
elif l == 3:
wrong_guess_2 = content_line
l = 4
Thank you quamrana, user1018651 and anyone who ave put a comment to help me !
Anyway, It still a 'little' thing to fix and I think this is the hardest one :
Transform this code for add the random questions and get, at end, this :
(the program take one question, randomly, in the whole file)
the chosen one
one of the three possibles guests
one other of the three possibles guests
a third possible guest
( And we don't know which one is the correct )
Answer :
Ok, so this look to be the final code :
for line in file:
# Remove trailing whitespace at the end of the line
content_line = line.rstrip()
if l == 0:
question = content_line
l = 1
elif l == 1:
right_guess = content_line
l = 2
elif l == 2:
wrong_guess_1 = content_line
l = 3
elif l == 3:
wrong_guess_2 = content_line
l = 4
Thank you quamrana, user1018651 and anyone who ave put a comment to help me !
Anyway, It still a 'little' thing to fix and I think this is the hardest one :
Transform this code for add the random questions and get, at end, this :
(the program take one question, randomly, in the whole file)
the chosen one
one of the three possibles guests
one other of the three possibles guests
a third possible guest
( And we don't know which one is the correct )
Answer :
answered Mar 7 at 16:41
EdhyjoxEdhyjox
5510
5510
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55048118%2fproblems-with-with-open-to-create-a-trivial-challenge-in-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
maybe look again at the number of equal signs in "if l = 4"
– Trilarion
Mar 7 at 16:09
4
Please show actual code. There are at least three typos in this code that would prevent it from running at all; so how can we know what is causing your issue?
– Daniel Roseman
Mar 7 at 16:10
1
But also ask yourself why you are iterating through every character in a line and appending it to a list, if that isn't what you want the output to be.
– Daniel Roseman
Mar 7 at 16:11
@trilarion, just a error of myselft, cause I've rewrite the whole program by hand ^^
– Edhyjox
Mar 7 at 16:12
1
FYI, the word is "guess", not "guest". A guest is a visitor.
– Barmar
Mar 7 at 16:13